gcc不接受默认模板参数中的包扩展 [英] gcc doesn't accept pack expansion in default template argument

查看:40
本文介绍了gcc不接受默认模板参数中的包扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码已使用clang成功编译,但gcc失败:

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)说

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和3.5.0没有错误.

clang 3.6.0 and 3.5.0 gives no errors.

我和clang违反了c ++规则吗?还是gcc错误?

Am I and clang violating c++ rules or is this a gcc bug?

推荐答案

您没有违反任何规则.GCC支持变量模板,不仅是默认参数,这似乎是一个问题,因为此调整有效:

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

据我所知,变量模板等效于包装静态成员的类模板,因此除了需要编写 :: v 之外,这不会引起任何问题.

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.

这篇关于gcc不接受默认模板参数中的包扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆