[英]Specialize template template parameter with a non-type template parameter
I'm trying to have partial specialization of a class template, where one template parameter is a template template parameter containing a single non-type parameter.我正在尝试对类模板进行部分特化,其中一个模板参数是包含单个非类型参数的模板模板参数。 For example:
例如:
template <
class T,
template <class Result, Result> class BinaryOperation
>
struct Foo;
template <
template <class Result, Result> class BinaryOperation
>
struct Foo<
int,
BinaryOperation
>
{ };
This code compiles fine using GCC-4.9.2.这段代码使用 GCC-4.9.2 编译得很好。
However, using Clang-4.0, I get a cryptic error message:但是,使用 Clang-4.0,我收到一条神秘的错误消息:
$ clang++-4.0 test.cpp -o test -std=c++14 -stdlib=libc++
test.cpp:18:3: error: template template argument has different template parameters than its corresponding template template
parameter
BinaryOperation
^
test.cpp:14:33: note: template non-type parameter has a different type 'Result' in template argument
template <class Result, Result> class BinaryOperation
^
test.cpp:9:33: note: previous non-type template parameter with type 'Result' is here
template <class Result, Result> class BinaryOperation
I've been Googling around for this error message, but it's very unclear to me.我一直在谷歌上搜索这条错误消息,但我很不清楚。 It seems to be saying that
Result
is somehow considered a different type when it appears as a template parameter versus when it appears as one of the arguments to the specialization list.似乎是说当
Result
作为模板参数出现时,与作为专业化列表的参数之一出现时,以某种方式被认为是不同的类型。
It works on GCC-4.9.2, so I don't know if this is a problem with Clang 4, or if GCC-4.9.2 is allowing something that it shouldn't.它适用于 GCC-4.9.2,所以我不知道这是否是 Clang 4 的问题,或者 GCC-4.9.2 是否允许它不应该的东西。
So why does Clang-4 report this compiler error?那么为什么 Clang-4 会报告这个编译器错误呢?
There is a bug reported on Clang bugzilla for this titled: Alias template produces seemingly bogus "template template argument has different template parameters" error在 Clang bugzilla 上报告了一个错误,标题为:别名模板产生看似虚假的“模板模板参数具有不同的模板参数”错误
This bug can be resolved in Clang 4 with the compiler option -frelaxed-template-template-args
.这个错误可以在 Clang 4 中使用编译器选项
-frelaxed-template-template-args
。
This has been fixed in later versions of Clang (from 5.0.0 onwards).这已在更高版本的 Clang 中得到修复(从 5.0.0 开始)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.