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

--- Comment #1 from Amir Kirsh <kirshamir at gmail dot com> ---
For user defined type this behavior might be ok, as the order of evaluation of
parameters is not defined, however this behavior is reflected also for
primitive types:

int main() {
    int a {5};
    (a += 1) += a;
    std::cout << a << std::endl;
}

gcc gives a warning:

warning: operation on 'a' may be undefined [-Wsequence-point]

    5 |     (a += 1) += a;

      |     ~~~^~~~~

<source>:5:8: warning: operation on 'a' may be undefined [-Wsequence-point]

and result is 12.

Though based on C++17 sequencing rules for assignment, seems that the operation
shall be valid (no warning) and result with 11.

http://eel.is/c++draft/expr.ass#1


Code: https://godbolt.org/z/G1Kahh

Reply via email to