问题描述
我有以下结构的代码(这当然在现实中要复杂得多,尤其是Base"是一个三行,但我试图抓住它的要点):
template A类{};模板B类{上市:B(){};};模板C类:公共B<A>>{上市:使用基数=B<A>>;使用 Base::B;};static const CC{};
代码通过 g++ 编译得很好
g++ -c test.cpp -std=c++11
但是,使用 clang++ 我收到一条我不太明白的错误消息
clang++ -c test.cpp -std=c++11
<块引用>
test.cpp:14:14: 错误:依赖使用声明解析为没有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 编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!