Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc doesn't accept pack expansion in default template argument

Tags:

c++

gcc

c++11

clang

Following code is compiled successfully with clang, but gcc fails:

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 violating c++ rules or is this a gcc bug?

like image 343
akakatak Avatar asked May 12 '15 02:05

akakatak


1 Answers

You haven't violated any rule. It appears to be a problem with GCC's support for variable templates, not only default arguments, because this adjustment 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 wrapping a static member, so this shouldn't cause any problems besides needing to write the ::v.

like image 164
Potatoswatter Avatar answered Sep 26 '22 06:09

Potatoswatter