【发布时间】:2019-03-04 04:34:07
【问题描述】:
我正在尝试对类模板进行部分特化,其中一个模板参数是包含单个非类型参数的模板模板参数。例如:
template <
class T,
template <class Result, Result> class BinaryOperation
>
struct Foo;
template <
template <class Result, Result> class BinaryOperation
>
struct Foo<
int,
BinaryOperation
>
{ };
这段代码使用 GCC-4.9.2 编译得很好。
但是,使用 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
我一直在谷歌搜索此错误消息,但我不清楚。似乎是说Result 在以模板参数的形式出现时与作为特化列表的参数之一出现时被认为是不同的类型。
它适用于 GCC-4.9.2,所以我不知道这是否是 Clang 4 的问题,或者 GCC-4.9.2 是否允许它不应该的东西。
那么为什么 Clang-4 会报告这个编译器错误呢?
【问题讨论】:
-
也没有来自 gcc 8.3 的投诉,而且我没有发现任何明显的问题。