Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isn't non-type parameter pack that evaluates to "void..." illegal?

gcc-4.8 accepts this code, but isn't it wrong since the non-type parameter pack is equivalent to void... which is illegal?

template <typename T,
          typename std::enable_if<std::is_integral<T>::value>::type...>
void test(T) {}

I tried this with clang-3.5 as well which also accepts it. Is this a compiler bug, or am I misunderstanding something?


Full test code below, which uses non-type empty parameter packs to simplify enable_if. This is almost the same as what's in Flaming Dangerzone's Remastered enable_if except after substitution the pack becomes void....

#include <type_traits>

template < typename C >
using enable_if_t = typename std::enable_if<C::value>::type ;

template < typename T, enable_if_t<std::is_integral<T>>... >
void test(T){} // #1

template < typename T, enable_if_t<std::is_floating_point<T>>... >
void test(T){} //#2

int main()
{
   test(0);   // calls #1
   test(0.0); // calls #2
   return 0;
}

gcc-4.8 compiles the above code just fine. clang doesn't but that's because it has a different bug http://llvm.org/bugs/show_bug.cgi?id=11723.

like image 679
Hui Avatar asked May 01 '14 02:05

Hui


1 Answers

After much searching in the context of another question, I have found a bit in the standard that clearly states this is illegal:

[temp.res]/6.3:

The program is ill-formed, no diagnostic required, if: ... every valid specialization of a variadic template requires an empty template parameter pack

So, the program is ill-formed, and compilers are not required to warn you about it.

like image 118
zennehoy Avatar answered Oct 01 '22 17:10

zennehoy