On 25/11/2019 12:02, Cristiano Di Buduo wrote:
On Sat, 23 Nov 2019 at 13:56, Jonny Grant <
jg@xxxxxxxx
<mailto:jg@xxxxxxxx>
> 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?
Why do you expect a different result for these?
A small = 1 << 40;
B big = 1 << 40;
In both cases the expression is 1 << 40, the type of A or B is irrelevant.
And the default type of a numeric constant is always int. (32 bits).
To make the warning go away, typecast the '1' to a size_t first.
Thank you for your replies. I mistakenly expected it to use the size_t type.
I filed a ticket, for GCC to make a suggestion that was appropriate ie. 1UL
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92659
And some other related that I thought of:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92660
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92642
Jonny