[Bug c++/103826] Bogus shift-negative-value warning in C++20 mode

manx-bugzilla at problemloesungsmaschine dot de gcc-bugzilla@gcc.gnu.org
Sat Dec 25 11:23:27 GMT 2021


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

--- Comment #2 from Jörn Heusipp <manx-bugzilla at problemloesungsmaschine dot de> ---
(In reply to Andrew Pinski from comment #1)

> Note I notice clang warns about:
> int main() {
>     return (0x7000'0000) << 4;
> }

It's valid, but clang complains here about shifting bits out of the range of
the target type:
warning: signed shift result (0x700000000) requires 36 bits to represent, but
'int' only has 32 bits [-Wshift-overflow]

It does not warn when only shifting into the sign bit (and not overflowing the
bits of the target type):
return (0x7000'0000) << 1;

I am not sure what the intended semantics of -Wshift-overflow is for clang, but
I have reported <https://github.com/llvm/llvm-project/issues/52873>.


More information about the Gcc-bugs mailing list