[cfe-dev] [patch] _Generic constant string used as controlling expression

Richard Smith richard at metafoo.co.uk
Mon Apr 28 11:36:48 PDT 2014


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140428/d1f96780/attachment.html>


More information about the cfe-dev mailing list