Stuart Henderson wrote:
> There are a fair few of these in c++ builds which tend to obscure some
> of the actually useful warnings. Antoine noticed it a while ago, Landry
> noticed it recently, I see it from time to time..
>
> Any suggestions other than not using -pedantic? (Actually I think
> I have seen this without -pedantic too somewhere but I forget where).
> Is this just a silly warning or is there actually a problem with the
> headers?
>
> This example is from chopping down a file from converters/wv2 (which
> is itself a relatively small example) until the warning no longer
> occurs then going back one step.
>
> $ cat > a.c
> #include <string>
> ^D
> $ c++ -pedantic -c a.c
> In file included from /usr/include/g++/memory:60,
> from /usr/include/g++/string:48,
> from a.c:1:
> /usr/include/g++/limits: In static member function 'static char
> std::numeric_limits<char>::min()': /usr/include/g++/limits:375: warning:
> overflow in implicit constant conversion /usr/include/g++/limits: In
> static member function 'static wchar_t
> std::numeric_limits<wchar_t>::max()': /usr/include/g++/limits:530:
> warning: overflow in implicit constant conversion
Not a solution, but hopefully helpful.
If I interpreted everything correctly, the macro __glibcxx_min
in /usr/include/g++/limits is used in std::numeric_limits<char>::min().
It uses something like ((char)1<<7) to determine the minimum value of a
char. I suspect that ((char)1<<7), or (1<<7) before being converted to
char, is interpreted as 128 in an intermediate stage of the processing.
When being pedantic 128 wouldn't fit in a char at that moment.
(AFAICT -128 <= char <= 127)
I suspect something similar is the case for the max function. 128 is used as
an intermediate result. Subtracting 1 gets the proper end result. But the
intermediate result (128) doesn't fit in a char when having a pedantic look
at this.
Attached is the simplest case I could come up with to reproduce this:
btw, this is on:
OpenBSD 5.0 (GENERIC.MP) #63: Wed Aug 17 10:14:30 MDT 2011
[email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
make a file, e.g. t.cc, containing:
char
test1()
{
return ((char)1<<6);
}
char
test2()
{
return ((char)1<<7);
}
char
test3()
{
return ((char)1<<8);
}
compile using C++ compiler:
being pedantic:
$ c++ -pedantic -c t.cc
t.cc: In function 'char test2()':
t.cc:11: warning: overflow in implicit constant conversion
t.cc: In function 'char test3()':
t.cc:18: warning: overflow in implicit constant conversion
NOT being pedantic:
$ c++ -c t.cc
t.cc: In function 'char test3()':
t.cc:18: warning: overflow in implicit constant conversion
copy to a .c file:
$ cp t.cc t.c
compile using C compiler:
being pedantic:
$ cc -pedantic -c t.c
t.c: In function 'test2':
t.c:11: warning: overflow in implicit constant conversion
t.c: In function 'test3':
t.c:18: warning: overflow in implicit constant conversion
NOT being pedantic:
$ cc -c t.c
t.c: In function 'test3':
t.c:18: warning: overflow in implicit constant conversion