将代码从gcc移植到clang
Porting code from gcc to clang
你好,我正试图使我的代码在clang 3.2-9下编译,这里是一个我无法编译的简化示例:
template<template <class>class Derived, typename Type>
class Foo
{
public:
Foo(){}
};
template<typename Type>
class Bar
: public Foo<Bar, Type>
{
public:
Bar()
: Foo<Bar, Type>()
{}
};
int main()
{
Bar<int> toto;
}
下面是clang告诉我的错误:
test.cpp:14:19: error: template argument for template template parameter must be a class template
: Foo<Bar, Type>()
^
test.cpp:14:15: error: expected class member or base class name
: Foo<Bar, Type>()
^
test.cpp:14:15: error: expected '{' or ','
3 errors generated.
在gcc 4.7.2下编译没有任何问题。而且我找不到正确的语法使它在clang下工作。谁能帮帮我,我有点卡住了…
为你的类模板使用完全限定名:
template<template <class> class Derived, typename Type>
class Foo
{
public:
Foo(){}
};
template<typename Type>
class Bar
: public Foo<::Bar, Type>
// ^^^^^
{
public:
Bar()
: Foo<::Bar, Type>()
// ^^^^^
{}
};
int main()
{
Bar<int> toto;
}
问题是在Bar
中,名称Bar
指的是类本身,即Bar
类模板(即Bar<Type>
)的实例化,而不是模板本身。
相关文章:
- 奇怪的结构&GCC&clang(void*返回类型)
- 数据成员SFINAE的C++17测试:gcc vs clang
- 在clang++预处理器中确定gcc工具链版本
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- 如何使用Clang/GCC在Mac上为C/C++设置VSCode
- 一位朋友将模板函数缩写为clang和gcc
- 类模板参数推导-clang和gcc不同
- GCC和Clang在与__builtin_constant_p相关的static_assert方面有所不同
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- MSVC发现这种方法调用模棱两可,而Clang / GCC则不然吗?
- Clang&GCC以不同的方式诠释系列演员表
- MSVC:无法识别的模板声明/定义(使用 Clang/GCC 编译)
- 构造函数上的SFINAE在VC2017中工作,但在clang / gcc中不起作用
- clang/GCC编译器内在的无相应编译器标志
- Clang & GCC 误推模板参数
- Clang & GCC 在使用智能指针时不会警告非虚拟基析构函数的多态性?
- Clang/GCC插件,用于解释自定义的c++11属性
- sscanf中uint16_t的正确且可移植的(Clang/GCC)修饰符是什么
- 依赖模板可以在Visual Studio中编译,但在clang/gcc中失败