'using'语句使用g ++编译,使用clang编译失败 [英] A 'using' statement compiles with g++, fails compilation with clang
问题描述
我有以下结构的代码(实际上实际上要复杂得多,尤其是 Base是三层结构,但我试图抓住它的要旨)
I have code of the following structure (which is of course much more complex in reality, especially "Base" is a three-liner, but I've tried to capture the gist of it):
template <class T>
class A {};
template <class T>
class B {
public:
B(){};
};
template <class T>
class C : public B<A<T>> {
public:
using Base = B<A<T>>;
using Base::B;
};
static const C<int> c{};
代码可以通过gp ++很好地通过
The code compiles fine with g++ via
g++ -c test.cpp -std=c++11
但是,使用clang ++时,我收到一条错误消息,我不太理解
However, with clang++ I get an error message I don't really understand
clang++ -c test.cpp -std=c++11
test.cpp:14:14:错误:依赖使用声明解析为不使用'typename'
使用Base :: B;
test.cpp:14:14: error: dependent using declaration resolved to type without 'typename' using Base::B;
我的代码有什么问题吗
注意:使用B< A< T>> :: B; $ c编写时$ c>可以在两个编译器上正常编译,但这不是解决我问题的真正方法。
Note: When writing using B<A<T>>::B;
it compiles fine with both compilers, but this not a real solution to my problem.
编辑:clang版本是3.5.0,gcc版本是4.9.2
clang version is 3.5.0, gcc version is 4.9.2
推荐答案
此案例已在C ++委员会中进行了讨论(根据Richard Smith https://llvm.org /bugs/show_bug.cgi?id=23107#c1 ),现在事情变得更加清晰:
This case has been discussed in the C++ committee (according to Richard Smith https://llvm.org/bugs/show_bug.cgi?id=23107#c1) and things have gotten clearer now:
using Base::B
不是有效的代码。
以下方法是引入类别名 Base
时表示构造函数继承的正确方法:
The following method is the correct way to express constructor inheritance when introducing a class alias Base
:
using Base::Base
但是,由clang产生的错误消息具有误导性,有望作为此错误报告的一部分得到解决( https://llvm.org/bugs/show_bug.cgi?id=22242 )。
However, the error messages produced by clang are misleading and will hopefully be solved as part of this bug report (https://llvm.org/bugs/show_bug.cgi?id=22242).
这篇关于'using'语句使用g ++编译,使用clang编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!