Strange error message from an incorrect typedef

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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]'.






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux