[patch] _Generic constant string used as controlling expression

Hi,
   I had reported this bug earlier:
http://clang-developers.42468.n3.nabble.com/Generic-constant-string-as-controlling-expression-td4036519.html

For following case:
int main(void)
{
  int x = _Generic("hello", char *: 1);
}

clang gives error:
generic_expr.c:3:20: error: controlling expression type 'char [6]' not
compatible with any generic association type
int x = _Generic ("hello", char *: 1);

I guess that's because array-to-pointer conversion is not performed
when array is used as controlling expression.
gcc-4.9 compiles the above test-case.

I have attached a patch that performs array-to-pointer conversion
when array is used as controlling expression, and it compiles the
above test-case.
OK to commit ?

Thanks and Regards,
Prathamesh

genericexpr.patch (663 Bytes)

This isn't quite the right approach -- it will still do the wrong thing if
a function designator is used as the argument to _Generic. You should use
DefaultFunctionArrayConversion here instead, replacing the existing
placeholder handling with it.

Thanks. I modified the patch to call DefaultFunctionArrayConversion.
Is it correct ?

Thanks and Regards,
Prathamesh

generic-expr.patch (552 Bytes)

No, you still don't handle function types. Please remove the (redundant)
handling of placeholder expressions too.

Sorry, didn't get that earlier.
The current patch removes handling of placeholder expression and calls
DefaultFunctionArrayConversion.

Following test-cases compile:
// check for function-designator
unsigned foo(void)
{
  return 0x03041992;
}

int main()
{
int x = _Generic (foo, unsigned (*)(void): 1);
return x;
}

// check for array
int main()
{
  int x = _Generic ("hello", char *: 1);
  return x;
}

Is this patch correct ?

Thanks and Regards,
Prathamesh

generic-expr.patch (746 Bytes)

Looks great, thanks!