[cfe-dev] Incongruency in __builtin_constant_p with pointer argument

Abramo Bagnara abramo.bagnara at gmail.com
Wed Apr 27 14:30:50 PDT 2011


$ cat t.c
typedef const int * ptr;

const int i = 0;
const ptr p = &i;

int a[__builtin_constant_p(i) ? 1 : -1];
int b[__builtin_constant_p(p) ? 1 : -1];

$ clang -S t.c
t.c:7:7: error: 'b' declared as an array with a negative size
int b[__builtin_constant_p(p) ? 1 : -1];
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
$ gcc -S t.c
t.c:6: error: size of array ‘a’ is negative
t.c:7: error: size of array ‘b’ is negative

I'm perfectly fine with the fact that clang treats const typed variable
as evaluatable constant (although gcc don't), but this should be the
same for both cases.

The fix is trivial and I'll commit it myself, but before I'd like to
know if it is preferred that __builtin_constant_p returns true for both
or false for both.



More information about the cfe-dev mailing list