_Generic constant string as controlling expression

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 ?

Thanks and Regards,
Prathamesh

"Convertible" does not mean "compatible", neither is a subset
of another; see 6.2.7.

At least, an array type is not compatible with a non-array type,
like a pointer.

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!

I don't think so. It looks more like an overlook to me. CC'ed Clark (the
author of _Generic).

At a first glance, performing an array-to-pointer conversion make things
easier, but imagine something like this:

  #define F(e) _Generic(e, char *: sizeof(e))

So what, sizeof a pointer is the array length? This leads very obscure
programs. Please don't. In unevalued context (stealing C++ term here),
no convert should be performed.

Here is an solution (no matter this is a bug in which side):

  http://stackoverflow.com/questions/18857056/c11-generic-how-to-deal-with-string-literals

>> 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!

I don't think so. It looks more like an overlook to me. CC'ed Clark (the
author of _Generic).

See also http://gcc.gnu.org/ml/gcc-patches/2013-07/msg00971.html and in
particular:

  "The controlling expression of a generic selection was very carefully
  not added to the list of contexts in which lvalue conversion is not
  done and type qualification is discarded", the minutes [from the C
  committee meeting] say

At a first glance, performing an array-to-pointer conversion make things

That’s http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1693.pdf page 19.

OK. Thanks. Then it needs to be careful when use it in C++ templates.

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!

I browsed through the bug database, it seems it was already
reported: http://llvm.org/bugs/show_bug.cgi?id=16340

Is the following fix correct ? After applying it, the error didn't get reported.

Index: SemaExpr.cpp