[cfe-dev] _Generic constant string as controlling expression
richard at metafoo.co.uk
Mon Dec 9 00:17:32 PST 2013
On Sun, Dec 8, 2013 at 2:16 PM, Prathamesh Kulkarni <
bilbotheelffriend at gmail.com> wrote:
> I am not able to understand why does the following code
> fail to compile:
> int main(void)
> 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 $126.96.36.199 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
> be converted from char to char * when it's used as a controlling
> expression ?
> Or am I missing something ?
Yes, I think it should -- this looks like a bug. Please file a bug report!
> Thanks and Regards,
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev