[cfe-dev] Noreturn adjustment for template functions

John McCall rjmccall at apple.com
Sat Feb 16 17:23:40 PST 2013


On Feb 16, 2013, at 5:18 AM, Alexander Zinenko <ftynse at gmail.com> wrote:
> +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 <typename T>
> void __attribute__((noreturn)) tfunc(T t) {}
> 
> typedef void (*ptr)(int);
> 
> void foo(ptr p) {}
> 
> void bar() {
>   foo(func); // Okay
>   foo(tfunc<int>); // 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.



More information about the cfe-dev mailing list