shift-count-overflow possible issue on 64bit type

Jonny Grant jg@jguk.org
Sun Nov 24 01:15:00 GMT 2019


Many thanks

I've filed a ticket, hope the warning can be enhanced.


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

Jonny


On 23/11/2019 14:15, Ponnuvel Palaniyappan wrote:
> The shift actually happens as int because the type of 1 is int, and 
> the result is then assigned to size_t. You can instead use a wider type:
>
> size_t big = 1UL<<41;
>
> On Sat, 23 Nov 2019, 13:56 Jonny Grant, <jg@jguk.org 
> <mailto:jg@jguk.org>> wrote:
>
>     I see on my 64bit Ubuntu PC that size_t is 8 bytes, that is 64bits,
>     however I see a warning:
>
>     $ g++-8 -Wall -Wextra -o size_t size_t.cpp
>     size_t.cpp: In function ‘int main()’:
>     size_t.cpp:11:21: warning: left shift count >= width of type
>     [-Wshift-count-overflow]
>           size_t big = 1<<40;
>                           ^~
>
>
>
>     Same on Godbolt trunk.
>     Is this an issue?
>
>     Regards, Jonny
>
>     https://godbolt.org/z/xeefQ8
>
>     #include <stdio.h>
>     size_t big = 1<<41;
>
>
>
>     Please keep my email on any replies
>     Jonny
>



More information about the Gcc-help mailing list