Strange error message from an incorrect typedef

Edward Diener eldlistmailingz@tropicsoft.com
Tue Sep 24 05:50:00 GMT 2019


The program is simply:

typedef int test_line[(0 == 1) ? 1 : -1];

int main()
     {
     return 0;
     }

Please do not ask why as this is just an example. If I compile the above 
source as test_typedef.cpp using gcc-9.2 with -m64 and -std=c++11 I 
receive the error messages of:

  test_typedef.cpp:1:40: error: narrowing conversion of '-1' from 'int' 
to 'long long unsigned int' [-Wnarrowing]
      1 | typedef int test_line[(0 == 1) ? 1 : -1];
        |                                        ^
  test_typedef.cpp:1:32: error: size '-1' of array 'test_line' is negative
      1 | typedef int test_line[(0 == 1) ? 1 : -1];
        |                       ~~~~~~~~~^~~~~~~~

While I am expecting the second error, why am I getting the first error 
? Why is an array bounds a 'long long unsigned int' and why is 
converting from an 'int' to a 'long long unsigned int' a narrowing 
conversion ?

If I change the typedef line to:

typedef int test_line[(1 == 1) ? 1 : -1];

and compile I do not get an error telling me 'narrowing conversion of 
'1' from 'int' to 'long long unsigned int' [-Wnarrowing]'.





More information about the Gcc-help mailing list