public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94429] New: Bogus sequence point warning
@ 2020-04-01  7:35 ofekshilon at gmail dot com
  2020-04-01 20:48 ` [Bug c++/94429] " pinskia at gcc dot gnu.org
  2020-04-01 23:29 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: ofekshilon at gmail dot com @ 2020-04-01  7:35 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/94429] Bogus sequence point warning
  2020-04-01  7:35 [Bug c++/94429] New: Bogus sequence point warning ofekshilon at gmail dot com
@ 2020-04-01 20:48 ` pinskia at gcc dot gnu.org
  2020-04-01 23:29 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-01 20:48 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>But this option will still warn about them, to help people avoid writing code that is undefined in C and earlier revisions of C++.

It is documented that way.

You can disable the warning if you want.
Some folks write C and C++ code that is portable between the two.
Also this warning is easy to avoid.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/94429] Bogus sequence point warning
  2020-04-01  7:35 [Bug c++/94429] New: Bogus sequence point warning ofekshilon at gmail dot com
  2020-04-01 20:48 ` [Bug c++/94429] " pinskia at gcc dot gnu.org
@ 2020-04-01 23:29 ` redi at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2020-04-01 23:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-04-01
             Status|RESOLVED                    |NEW
         Resolution|INVALID                     |---

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I asked  the reporter to file this bug, because I think the warning should say
"may be undefined in C and older versions of C++" or something like that.

It's fine to warn (as documented) but the text of the warning should be
accurate. If it's 100% guaranteed to be not undefined in the current
translation unit, it's wrong to say "may be undefined".

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-01 23:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-01  7:35 [Bug c++/94429] New: Bogus sequence point warning ofekshilon at gmail dot com
2020-04-01 20:48 ` [Bug c++/94429] " pinskia at gcc dot gnu.org
2020-04-01 23:29 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).