While trying to understand how all the template magic in C++ 20 works I stumbled upon the following (which is probably not really related to C++ 20):
My compiler (Visual C++ 2022) accepts the following code:
template<typename X,typename Y>
constexpr int UselessVar = 42;
template<typename X>
char* UselessVar <X,X> = "Donald Duck";
auto Blabla1 = UselessVar<int,int>;
auto Blabla2 = UselessVar<int*,int**>;
Code compiles and indeed Blabla1 is a 'constexpr int' and Blabla2 a 'char*'.
I am wondering: Does a template specialisation really allow me to change both "constness" and type of the underlying variable or is this a glitch of this compiler? This seems pretty weird to me. Beside use cases like "changing the type of a return value from a base class to a derived class" I cannot really think of a good use-case for something in that direction and somehow from "gut-feeling" I would assume that this kind of "changing the type to something completely different" should be forbidden?!