[cfe-dev] _Generic with __attribute__((overloadable))

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 30 12:34:11 PDT 2016


On Tue, Aug 30, 2016 at 3:11 PM, Nemanja Ivanovic via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> Rather than opening a bug, I thought I'd check if this is supposed to work
> (given that the overloadable attribute is an extension).
>
> Should this compile and have the expected semantics (i.e. call the int
> version):
>
> int __attribute__((overloadable)) test (int);
> double __attribute__((overloadable)) test (double);
> char testc(char);
>
> #define testm(X) \
>   _Generic ((X), \
>             char : testc, \
>             default: test) (X)
>
>
> int foo() {
>   return testm(4);
> }
>
> It appears that the _Generic macro triggers overload resolution of some sort
> which resolves the call to yet another overloaded function. So we hit an
> UNREACHABLE in  Sema::FixOverloadedFunctionReference.
>
> If the argument in the call is replaced with a char value, there is no
> crash.
>
> In any case, presumably this crash behaviour should perhaps be improved with
> a diagnostic.

The crash is definitely a bug, and we should either fix it with a
diagnostic, or handle the overloadable attribute more sensibly. Can
you file this as a bug (https://llvm.org/bugs)?

Thanks!

~Aaron

>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list