gcc doesn't accept pack expansion in default template argument

不想你离开。 提交于 2021-02-07 06:34:31

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30180847/gcc-doesnt-accept-pack-expansion-in-default-template-argument

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