我正在尝试对类模板进行部分专门化,其中一个模板参数是一个包含单个非类型参数的模板参数。例如:
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会报告这个编译器错误呢?
发布于 2019-03-04 12:53:31
在Clang bugzilla上有一个bug,标题是:Alias template produces seemingly bogus "template template argument has different template parameters" error
在Clang 4中,可以使用编译器选项-frelaxed-template-template-args解决此错误。
参见demo here。
在更高版本的Clang中已修复此问题(从5.0.0开始)。
https://stackoverflow.com/questions/54976674
复制相似问题