繁体   English   中英

扩展非类型参数包以使用非类型模板参数定义内部类模板是否合法?

[英]Is it legal to expand non-type parameter pack to define internal class template with non-type template parameters?

我能够生成以重现该问题的最少代码:

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 ++(版本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; 

并产生冗长而乏味的堆栈跟踪。 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;
}

那么这是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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM