By looking at the following code, I am confused by line 3.
Line 3 is not a special case of the base template, it is more like a “class overload”. But it can be compiled successfully.
The obj1 in line 7 is defined according to line 3, but failed to compile.
How come?
template<typename S,int T, void(* U)()> class Bar{}; // Base template
template<int T, void(* U)()> class Bar<double, T, U>{}; // Specialization, which is good
template<int T, void(* U)()> class Bar<double, U, T>{}; // Also good, how come?
void func(){};
int main(){
//Bar<double, func, 1> obj1; // Error, from line 3
}
As long as that form is not used anywhere – then the compiler will not complain. If it is used, and the compiler has to instantiate – then it will complain. Which is why if you uncomment, you get the error – at this point, the compiler sees the flawed partial specialization.