https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84686

            Bug ID: 84686
           Summary: Parenthesized discarded value expression are not
                    evaluated with option -std=c++14
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: okannen at gmail dot com
  Target Milestone: ---

This bug appears first in version 4.9 and is still here in version 7.3 and
above.

Compilation option: -std=c++14 or a newer c++ version.

*Description:

  Evaluation of discarded value expression are not performed if the expression
is parenthesized:

     volatile int i;

     i; //evaluated (a load is performed)
     (i); //unevaluated => the load shall be performed

     (void)i; //evaluated (a load is performed)
     (void)(i); //unevaluated => the load shall be performed

     (void)i; //evaluated (a load is performed)
     (void)(i); //unevaluated => the load shall be performed

     (i,i); // the two subexpression are evaluated
     ((i),(i)); // no evaluation, => two loads shall happen

Remark: Clang does perform all loads.

*C++ standard requirements (N4140)

**[expr.prim.general]/6:
  A parenthesized expression is a primary expression whose type and value are
identical to those of the enclosed expression. The presence of parentheses does
not affect whether the expression is an lvalue. The parenthesized expression
can be used in exactly the same contexts as those where the enclosed expression
can be used, and with the same meaning, except as otherwise indicated.

**[expr]/11:
  In some contexts, an expression only appears for its side effects. Such an
expression is called a discarded-value expression. The expression is evaluated
and its value is discarded. The array-to-pointer ([conv.array]) and
function-to-pointer ([conv.func]) standard conversions are not applied. The
lvalue-to-rvalue conversion ([conv.lval]) is applied if and only if the
expression is a glvalue of volatile-qualified type and it is one of the
following:
  - ( expression ), where expression is one of these expressions,
  - [...]

Reply via email to