[cfe-dev] why do i get the "c++11-narrowing" warning only in switch using defines?
Richard Smith
richard at metafoo.co.uk
Mon May 11 09:57:07 PDT 2015
On Mon, May 11, 2015 at 2:23 AM, Dennis Luehring <dl.soluz at gmx.net> wrote:
> #define TEST0 0xFFFA0000
> #define TEST1 0xFFFA0001
>
> const int test0 = 0xFFFA0000;
> const int test1 = 0xFFFA0001;
>
> int main(int argc, char** arcv)
> {
> if(argc == TEST0) // OK
> {
> return 1;
> }
>
> if(argc == test0) // OK
> {
> return 1;
> }
>
> switch(argc)
> {
> case TEST1: return 2; // ERROR: case value evaluates to 4294574081,
> which cannot be narrowed to type 'int' [-Wc++11-narrowing]
>
The value here is unsigned, and doesn't fit in an int.
> }
>
> switch(argc)
> {
> case test1: return 2; // OK
>
The value here is signed; the conversion to int happened in the variable
declaration.
> }
> }
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150511/33897646/attachment.html>
More information about the cfe-dev
mailing list