首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用非类型模板参数专门化模板模板参数

使用非类型模板参数专门化模板模板参数
EN

Stack Overflow用户
提问于 2019-03-04 12:34:07
回答 1查看 148关注 0票数 2

我正在尝试对类模板进行部分专门化,其中一个模板参数是一个包含单个非类型参数的模板参数。例如:

代码语言:javascript
复制
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时,我得到了一条隐秘的错误消息:

代码语言:javascript
复制
$ 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会报告这个编译器错误呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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开始)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54976674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档