Gcc does not accept package extension in default template argument

The following code compiled successfully with clang, but gcc does not work:

struct fn { template <typename ... Args> static constexpr bool call (Args ... ) { return true; } }; template <typename ... T> static constexpr bool f = false; template <typename ... Ts, bool F = fn::call(f<Ts> ...)> void hoge () {} int main () {} 

gcc 5.1.0 (-Wall -Wextra -std = C ++ 14 -pedantic) says

 prog.cc:10:52: error: expansion pattern 'f<Ts>' contains no argument packs template <typename ... Ts, bool F = fn::call(f<Ts> ...)> 

clang 3.6.0 and 3.5.0 gives no errors.

Am I and clang breaking C ++ rules or is this a gcc bug?

+6
source share
1 answer

You have not violated any rule. There seems to be a problem with GCC support for template variables, not just the default arguments, as this setting works:

 template <typename ... T> struct f { static constexpr bool v = false; }; template <typename ... Ts, bool F = fn::call(f<Ts>::v ...)> void hoge () {} 

http://coliru.stacked-crooked.com/a/ff81b6ab052a748b

As far as I know, a variable template is equivalent to a class template that carries a static member, so this should not cause any problems except the need to write ::v .

+4
source

Source: https://habr.com/ru/post/987011/


All Articles