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>.
  • [Bug c++/1038... manx-bugzilla at problemloesungsmaschine dot de via Gcc-bugs
    • [Bug c++... pinskia at gcc dot gnu.org via Gcc-bugs
    • [Bug c++... manx-bugzilla at problemloesungsmaschine dot de via Gcc-bugs

Reply via email to