Home > Software design >  ill-formed template partial specialization
ill-formed template partial specialization

Time:10-26

I am experimenting with template partial specializations and I have come to the following code.

template <typename T>
struct X {
    using type = T;
};

template <typename T>
struct Y {};

template <typename T>
struct Y<typename X<T>::type> {};

Clang, GCC, and MSVC seem to complain that the template parameter is not deducible in this context. However, the partial specialization should never be matched. Thus every specialization would rely on the the primary template definition.


I can't find the section in the specification which prohibits this.

CodePudding user response:

template <typename T>
struct Y<typename X<T>::type> {};

Is not more specialized than the primary class template.

template <typename T>
struct Y {};

In other words, it accepts the same set of types that the primary class template accepts, not a subset of it. The exact clause from the specification.

  • Related