[cfe-dev] _Generic constant string as controlling expression

Richard Smith 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 [6]' not compatible
> with any generic association type
>   int a = _Generic("hello", char *: 1);
>
> n1570 $6.3.2.1 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[6] 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,
> Prathamesh
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131209/3098e6ed/attachment.html>


More information about the cfe-dev mailing list