Noreturn adjustment for template functions

Hello cfe-dev!

+Richard Smith

Investigating another issue, I found out that an instantiated noreturn template function can’t be implicitly used as not-noreturn argument while non-template function can.
Here is an example:

void attribute((noreturn)) func(int i) {}

template
void attribute((noreturn)) tfunc(T t) {}

typedef void (*ptr)(int);

void foo(ptr p) {}

void bar() {
foo(func); // Okay
foo(tfunc); // Error: … candidate function ‘foo’ not viable
}

It is most likely due to noreturn function representation (there was a discussion on PR15105 lately). As far as I see, SemaOverload.cpp contains a special case for noreturn adjustment as an implicit conversion, but it doesn’t account for templates.

One would expect consistent behavior in this case, though.
Should I file a bug for it?

Yes. The problem is almost certainly that template argument deduction should permit an inexact match requiring a noreturn conversion in the same sorts of places that it would permit an inexact match requiring a qualification conversion.

John.

This is now PR15291. Thanks.