[cfe-dev] [patch] _Generic constant string used as controlling expression
Prathamesh Kulkarni
bilbotheelffriend at gmail.com
Mon Apr 28 11:58:01 PDT 2014
On Tue, Apr 29, 2014 at 12:06 AM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Mon, Apr 28, 2014 at 11:35 AM, Prathamesh Kulkarni
> <bilbotheelffriend at gmail.com> wrote:
>>
>> On Mon, Apr 28, 2014 at 11:48 PM, Richard Smith <richard at metafoo.co.uk>
>> wrote:
>> > On Mon, Apr 28, 2014 at 10:58 AM, Prathamesh Kulkarni
>> > <bilbotheelffriend at gmail.com> wrote:
>> >>
>> >> 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 ?
>> >
>> >
>> > 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 ?
>
>
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: generic-expr.patch
Type: text/x-patch
Size: 746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140429/32ecc0da/attachment.bin>
More information about the cfe-dev
mailing list