显然,以下代码无法在gcc 4.7上编译:
#include <vector>
struct foo {
std::vector<int> x;
template<typename T>
void bar(T) {
decltype(x)::value_type y;
}
};
int main() {
foo f;
f.bar(0);
}
编译错误如下:
test.cpp:8:9: error: need ‘typename’ before ‘decltype (((foo*)this)->foo::x)::value_type’ because ‘decltype (((foo*)this)->foo::x)’ is a dependent scope
我知道该问题的解决方案,但是为什么不编译呢?此处的
x
不是从属名称,因此,如果编译器已经可以自己弄清楚decltype(x)::value_type
的类型,为什么我需要显式指出x
是一种类型?还是我错了,所以ojit_code实际上是一个从属名称? 最佳答案
直到有人找到关于此的特定报告(我尝试查找并且找到的最接近的报告是this),然后才是does compile with GCC 4.8.0。基于这些信息和我之前的怀疑,我想说这只是GCC 4.7中的一个错误,该错误已修复为4.8。