[cfe-dev] why do i get the "c++11-narrowing" warning only in switch using defines?

Dennis Luehring dl.soluz at gmx.net
Mon May 11 21:15:19 PDT 2015


i changed the defined to

((int)0xFFFA0001) etc.

that makes it more clear

thx all


Am 11.05.2015 um 18:57 schrieb Richard Smith:
> 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
> >
>




More information about the cfe-dev mailing list