[cfe-dev] _Generic constant string as controlling expression
bilbotheelffriend at gmail.com
Sun Dec 8 14:16:09 PST 2013
I am not able to understand why does the following code
fail to compile:
int x = _Generic("hello", char *: 1);
Compiling it with clang-3.2 gives the following error:
f.c:5:20: error: controlling expression type 'char ' not compatible
with any generic association type
int a = _Generic("hello", char *: 1);
n1570 $22.214.171.124 3rd point states:
"Except when it is the operand of the sizeof operator, the _Alignof
operator, or the
unary & operator, or is a string literal used to initialize an array,
an expression that has type ‘‘array of type’’ is converted to an
expression with type ‘‘pointer to type’’ that points to the initial
element of the array object and is not an lvalue. If the array object
has register storage class, the behavior is undefined."
Since this clause has no mention for _Generic, shouldn't the type of "hello"
be converted from char to char * when it's used as a controlling expression ?
Or am I missing something ?
Thanks and Regards,
More information about the cfe-dev