public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jeff at jgarrett dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/105774] New: Bogus overflow in constant expression
Date: Mon, 30 May 2022 14:31:31 +0000	[thread overview]
Message-ID: <bug-105774-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2022-05-30 14:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 14:31 jeff at jgarrett dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105774-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).