isn't non-type parameter pack that evaluates to “void…” illegal?

左心房为你撑大大i 提交于 2019-12-18 02:41:15

问题


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 = typename std::enable_if<C::value>::type ;

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

template < typename T, enable_if<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.


回答1:


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]/8.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.



来源:https://stackoverflow.com/questions/23401376/isnt-non-type-parameter-pack-that-evaluates-to-void-illegal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!