public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105774] New: Bogus overflow in constant expression
@ 2022-05-30 14:31 jeff at jgarrett dot org
  2022-05-30 14:39 ` [Bug c++/105774] " klaus.doldinger64 at googlemail dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: jeff at jgarrett dot org @ 2022-05-30 14:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105774
           Summary: Bogus overflow in constant expression
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jeff at jgarrett dot org
  Target Milestone: ---

The following is diagnosed as ill-formed by GCC but not by Clang:

    int main() {
      constexpr auto _ = [] {
        char x = 127;
        return ++x;
      }();
    }

<source>:5:5: error: overflow in constant expression [-fpermissive]

On godbolt https://godbolt.org/z/91oeGsEbh
Originally from
https://stackoverflow.com/questions/72425404/still-unsure-about-signed-integer-overflow-in-c

I believe that this is well-formed. [expr.pre.incr]/1 says x++ is equivalent to
x+=1. [expr.ass]/6 says that x+=1 is equivalent to x=x+1 except that x is only
evaluated once. That expression x=x+1 avoids overflow through integer
promotion.

The same code with x+=1 instead of ++x is allowed by GCC.

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

end of thread, other threads:[~2023-05-04  7:17 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30 14:31 [Bug c++/105774] New: Bogus overflow in constant expression jeff at jgarrett dot org
2022-05-30 14:39 ` [Bug c++/105774] " klaus.doldinger64 at googlemail dot com
2022-06-01 11:40 ` rguenth at gcc dot gnu.org
2022-10-22 20:55 ` [Bug c++/105774] Bogus overflow in constant expression with signed char++ pinskia at gcc dot gnu.org
2022-10-22 20:56 ` pinskia at gcc dot gnu.org
2022-10-23 16:46 ` jakub at gcc dot gnu.org
2022-10-24 14:26 ` cvs-commit at gcc dot gnu.org
2022-10-25  9:05 ` jakub at gcc dot gnu.org
2022-11-03  0:23 ` cvs-commit at gcc dot gnu.org
2022-11-04  8:31 ` cvs-commit at gcc dot gnu.org
2023-05-03 15:19 ` cvs-commit at gcc dot gnu.org
2023-05-04  7:17 ` jakub 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).