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

--- Comment #4 from Jonny Grant <jg at jguk dot org> ---
This test case for similar does have a nice warning.

Interestingly, G++ does not indicate that 5147483647 is already 34 bits long:
100110010110100000101110111111111
which is more than an 'int' (32bit) which as Jonathan has highlighted, to be
the way numbers are treated in C/C++ when they do not have UL suffix.


#include <stdio.h>

int main()
{
size_t i = 5147483647 << 32;

printf("%zu\n", i);

}




#1 with x86-64 gcc (trunk)
<source>: In function 'int main()':
<source>:5:23: warning: result of '(5147483647 << 32)' requires 66 bits to
represent, but 'long int' only has 64 bits [-Wshift-overflow=]
    5 | size_t i = 5147483647 << 32;
      |            ~~~~~~~~~~~^~~~~

Reply via email to