问题描述
我有以下结构的代码(这在现实中当然要复杂得多,尤其是Base"是一个三行代码,但我试图抓住它的要点):
模板<class T>A类{};模板<T类>B类{上市:B(){};};模板<T类>C类:公共B<A<T>>{上市:使用 Base = B<A<T>>;使用 Base::B;};静态常量 C<int>C{};
代码通过 g++ 编译良好p>
g++ -c test.cpp -std=c++11
但是,使用 clang++ 我收到一条我不太明白的错误消息
clang++ -c test.cpp -std=c++11
<块引用>
test.cpp:14:14: 错误:依赖 using 声明解析为没有typename"的类型使用 Base::B;
我的代码有什么问题吗?或者这是 clang 中的错误?
注意:使用 B<A<T>>::B; 编写 时,两个编译器都可以正常编译,但这并不是我的问题的真正解决方案.
clang 版本是 3.5.0,gcc 版本是 4.9.2
这个案例已经在 C++ 委员会讨论过(根据 Richard Smith https://llvm.org/bugs/show_bug.cgi?id=23107#c1) 现在事情变得更清楚了:
使用 Base::B
不是是有效代码.
下面的方法是在引入类别名Base
时表达构造函数继承的正确方式:
使用 Base::Base
但是,clang 产生的错误消息具有误导性,并有望作为此错误报告的一部分得到解决 (https://llvm.org/bugs/show_bug.cgi?id=22242).
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{};
The code compiles fine with g++ via
g++ -c test.cpp -std=c++11
However, with clang++ I get an error message I don't really understand
clang++ -c test.cpp -std=c++11
test.cpp:14:14: error: dependent using declaration resolved to type without 'typename' using Base::B;
Is there anything wrong with my code or is this a bug in clang?
Note: When writing using B<A<T>>::B;
it compiles fine with both compilers, but this not a real solution to my problem.
Edit: clang version is 3.5.0, gcc version is 4.9.2
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
is not intended to be valid code.
The following method is the correct way to express constructor inheritance when introducing a class alias Base
:
using Base::Base
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 编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!