template<class T>
void fun(T){}
template<>
int fun(int){return 0;}
Consider this example, it is rejected by all implementations. However, I haven't found any persuasive provision in the current standard that specifies this explicit specialization declaration is ill-formed. If it exists, what is the rule?
In addition, the potential relevant rule may be that [temp.deduct.decl#2]
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.
I think the meaning of "match" is not sufficiently clear here since "match" didn't clearly define anything.
Your template definition did not match, as
void fun(T)is notT fun(T)in your specialization or maybe the other way around if you haveint fun(T)to specialize withint fun(int).You simply have to change to:
BTW: All this results in a lot of warning because you did not return anything :-)
Why it did not match:
expands for T=int to:
BUT: the specialization ( it isn't one, because it did not match )
has a return type which can never deduced from the original template definition, as this, it is never a specialization because it always has return type
voidwhile your specialization hasint.