W.F*_*.F. 5 c++ templates non-type variadic-templates c++14
我能够生成的最小代码来重现问题:
template <int>
struct Tag { };
Tag<0> w;
template <int... Is>
struct Outer {
template <Tag<Is> &...>
struct Inner {
};
};
int main() {
Outer<0>::Inner<w> f;
}
Run Code Online (Sandbox Code Playgroud)
g ++(版本6.1.1 20160511)在编译代码时遇到以下错误:
Run Code Online (Sandbox Code Playgroud)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;
并产生长而无聊的堆栈跟踪.版本3.6.0中的clang ++似乎没有编译代码的任何问题.具有类型模板参数的相同代码在两个编译器中编译得很好:
template <class>
struct Tag { };
Tag<int> w;
template <class... Ts>
struct Outer {
template <Tag<Ts> &...>
struct Inner {
};
};
int main() {
Outer<int>::Inner<w> f;
}
Run Code Online (Sandbox Code Playgroud)
那么这是一个g ++错误还是我遗漏了一些非类型可变参数模板参数扩展的重要内容,它不适用于类模板参数扩展?
(不是答案,但有人可能感兴趣)
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
167 次 |
| 最近记录: |