[Bug c++/94429] New: Bogus sequence point warning

ofekshilon at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Apr 1 07:35:42 GMT 2020


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

            Bug ID: 94429
           Summary: Bogus sequence point warning
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ofekshilon at gmail dot com
  Target Milestone: ---

This code:
int main() 
{
  int a = 1;
  a = ++a ;
}

built with -std=c++17 -Wall  (or just -Wsequence-point)
gives: 
<source>:4:5: warning: operation on 'a' may be undefined [-Wsequence-point]
    4 |   a = ++a ;
      |   ~~^~~~~

Since c++17 this is no longer undefined:
https://timsong-cpp.github.io/cppwp/n4659/expr.ass#1

Moreover, it seems that sometime ago the gcc team was aware of it:
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wsequence-point

"The C++17 standard will define the order of evaluation of operands in more
cases: in particular it requires that the right-hand side of an assignment be
evaluated before the left-hand side, so the above examples are no longer
undefined. But this option will still warn about them, to help people avoid
writing code that is undefined in C and earlier revisions of C++."

I (and others,
https://stackoverflow.com/questions/60937761/sequence-points-is-this-gcc-warning-a-bug)
consider this definitely a bug.  When I'm writing in C++17 and need to produce
warning-free code, I don't expect to work around the compiler saying I should
write code that would be valid in other language versions.


More information about the Gcc-bugs mailing list