_Generic with __attribute__((overloadable))

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.

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

OK, thank you.

Filed https://llvm.org/bugs/show_bug.cgi?id=30201