public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manx-bugzilla at problemloesungsmaschine dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/103826] New: Bogus shift-negative-value warning in C++20 mode
Date: Sat, 25 Dec 2021 10:26:11 +0000	[thread overview]
Message-ID: <bug-103826-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 103826
           Summary: Bogus shift-negative-value warning in C++20 mode
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: manx-bugzilla at problemloesungsmaschine dot de
  Target Milestone: ---

C++20 changed the semantics when shifting negative values from undefined
behavior to defined semantics. However, GCC still warns with -std=c++20 in this
case, which is unfortunate, because it generates a lot of warnings when porting
code to modern C++20. The warning is enabled by -Wextra.

```
int foo() {
    return (-32767) << 3;
}
```
`-std=c++20 -Wall -Wextra -Wpedantic`:
```
<source>: In function 'int foo()':
<source>:2:21: warning: left shift of negative value [-Wshift-negative-value]
    2 |     return (-32767) << 3;
      |            ~~~~~~~~~^~~~
```

Clang also warns in this case in C++17 mode, but does not warn in C++20 mode.
See <https://godbolt.org/z/8Yd9qfveP>.

             reply	other threads:[~2021-12-25 10:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-25 10:26 manx-bugzilla at problemloesungsmaschine dot de [this message]
2021-12-25 10:53 ` [Bug c++/103826] " pinskia at gcc dot gnu.org
2021-12-25 11:23 ` manx-bugzilla at problemloesungsmaschine dot de

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-103826-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).