[英]Is it legal to expand non-type parameter pack to define internal class template with non-type template parameters?
The minimal code I was able to generate to reproduce the problem: 我能够生成以重现该问题的最少代码:
template <int>
struct Tag { };
Tag<0> w;
template <int... Is>
struct Outer {
template <Tag<Is> &...>
struct Inner {
};
};
int main() {
Outer<0>::Inner<w> f;
}
g++ (version 6.1.1 20160511) encounters following error while compiling the code: g ++(版本6.1.1 20160511)在编译代码时遇到以下错误:
pp.cc: In function 'int main()': pp.cc:14:21: internal compiler error: unexpected expression 'Is' of kind template_parm_index Outer<0>::Inner<w> f;
And produces long and boring stack trace. 并产生冗长而乏味的堆栈跟踪。 clang++ in version 3.6.0 does not seem to have any problem with compiling the code.
3.6.0版中的clang ++似乎在编译代码方面没有任何问题。 The same code with type template parameters compiles just fine in both compilers:
带有类型模板参数的相同代码在两个编译器中都可以正常编译:
template <class>
struct Tag { };
Tag<int> w;
template <class... Ts>
struct Outer {
template <Tag<Ts> &...>
struct Inner {
};
};
int main() {
Outer<int>::Inner<w> f;
}
So is it a g++ bug or am I missing something important about non-type variadic template parameters expansion which does not apply to class template parameters expansion? 那么这是g ++的错误,还是我缺少关于非类型可变参数模板参数扩展的重要内容,而这些不适用于类模板参数扩展?
(Not an answer but someone might be interested) (不是答案,但可能有人感兴趣)
Possible relatively simple workaround for GCC: GCC可能相对简单的解决方法:
template <int>
struct Tag { };
Tag<0> w;
template <class... Ts>
struct OuterParent {
template <Ts&...>
struct Inner {
};
};
template <int... Is>
struct Outer:OuterParent<Tag<Is>...> {
};
int main() {
Outer<0>::Inner<w> f;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.