Both compilers are correct. From [temp.res]/8:
If no valid specialization can be generated for a template, and that template is not instantiated, the template is ill-formed, no diagnostic
required.
There does not exist a valid specialization that can be generated from the primary template Hitchhiker
, so it is ill-formed, no diagnostic required. clang chooses to issue a diagnostic anyway.
If you only want to allow 42
, then simply don’t define the general template:
template <int > struct Hitchhiker;
template <> struct Hitchhiker<42> {};