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.