Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack an explicit restriction on "return type" in the explicit function template instantiation/specialization #5163

Open
xmh0511 opened this issue Dec 22, 2021 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Dec 22, 2021

template<class T>
void fun(T){}

template<>
int fun(int){}

In the current draft, there's no formal provision that can prove the example is ill-formed. The only potential relevant rules are
[temp.deduct.decl] p2

If, for the set of function templates so considered, there is either no match or more than one match after partial ordering has been considered ([temp.func.order]), deduction fails and, in the declaration cases, the program is ill-formed.

"match" is vague and it is not sufficiently clear, consider the following example

template<class T>
auto fun(T){}

template<>
auto fun(int){
   return 0;
}

The above example is accepted by all implementations, what does "match" mean in this example?

@jensmaurer @opensdh

The "match" may have a clear definition instead. Such as

The function type of an explicit specialization shall be identical to the function type of the specialization that would be implicitly instantiated from the function template, except that, the function template has a declared return type that uses a placeholder type, which case is specified in [dcl.spec.auto].

The explicit instantiation declaration for a function template may have a similar restriction as to the above. Or, we should have a reference to [temp.deduct.decl] in a general rule for explicit specialization of a function template instead just mentions [temp.deduct.decl] in paragraph [temp.expl.spec] p10 that is not suitable for template<> void fun<int>(int);. BTW, since [temp.deduct.decl] p1 references to [temp.deduct.type] but that section lacks to specify the deduction of function type's return type with the form T.

@xmh0511 xmh0511 changed the title Lacks the restriction on "return type" in the explicit function template instantiation/specialization Lacks an explicit restriction on "return type" in the explicit function template instantiation/specialization Dec 22, 2021
@xmh0511 xmh0511 changed the title Lacks an explicit restriction on "return type" in the explicit function template instantiation/specialization Lack an explicit restriction on "return type" in the explicit function template instantiation/specialization Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant