简体   繁体   English

函数模板中的decltype和scope resolution运算符

[英]decltype and scope resolution operator inside a function template

Apparently, the following code does not compile on gcc 4.7: 显然,以下代码无法在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);
}

The compilation error is the following: 编译错误如下:

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

I know the solution to the problem, but why is it not compiling? 我知道问题的解决方案,但为什么不编译? x here is not a dependent name, so why do I need to explicitly indicate that decltype(x)::value_type is a type if the compiler can already figure that out by himself? 这里的x不是依赖名称,那么为什么我需要明确指出decltype(x)::value_type是一个类型,如果编译器已经可以自己解决这个问题了? Or am I wrong and x is actually a dependent name here? 或者我错了, x实际上是一个依赖名称?

Until someone finds a specific report on this (I tried looking and the closest I've found is this ), this does compile with GCC 4.8.0 . 直到有人找到一个特定的报告(我试过看,我发现最接近的是这个 ),这确实是用GCC 4.8.0编译的 Based on that information and my prior suspicions, I would say this is just a bug in GCC 4.7 that was fixed for 4.8. 根据这些信息和我之前的怀疑,我会说这只是GCC 4.7中的一个错误,修正了4.8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM