lundi 28 novembre 2016

Are checked guard parameter packs cause of ill-formed programs in case of specializations?

This is a follow-up on this question.

Consider the following code:

#include <type_traits>

template<typename T, typename... P, typename U = std::enable_if_t<std::is_integral<T>::value>>
void f() { static_assert(sizeof...(P) == 0, "!"); }

int main() {
    f<int>();
}

It compiles, but according to [temp.res]/8 it is ill-formed, no diagnostic required because of:

every valid specialization of a variadic template requires an empty template parameter pack

Now consider this slightly different example:

#include <type_traits>

template<typename T, typename... P, typename U = std::enable_if_t<std::is_integral<T>::value>>
void f() { static_assert(sizeof...(P) == 0, "!"); }

template<>
void f<int, int>() { }

int main() {
    f<int, int>();
}

In this case a valid full explicit specialization exists for which the parameter pack is not empty.
Does this suffice to say that the code is no longer ill-formed?


Note: I'm not looking for alternative ways like putting the std::enable_if_t in the return type or similar.

Aucun commentaire:

Enregistrer un commentaire