[cfe-dev] _Generic constant string as controlling expression

Richard Smith richard at metafoo.co.uk
Mon Dec 9 12:29:51 PST 2013


On Mon, Dec 9, 2013 at 12:26 PM, Zhihao Yuan <zy at miator.net> wrote:

> On Mon, Dec 9, 2013 at 3:17 AM, Richard Smith <richard at metafoo.co.uk>
> wrote:
> >> 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
> 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
>
> --
> Zhihao Yuan, ID lichray
> The best way to predict the future is to invent it.
> ___________________________________________________
> 4BSD -- http://4bsd.biz/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131209/69b5060d/attachment.html>


More information about the cfe-dev mailing list