c++ - 未评估上下文中的 "Cannot call member function ... without object"- GCC 错误?

标签 c++ gcc c++11

下面的程序用 Clang 编译得很好:

template< typename > struct X
{
  void foo() {}

  auto bar() -> decltype( X::foo() )
  {
    return foo();
  }
};

int main()
{
  X<int>().bar();
}

但是 GCC 4.8.1 给出了:

main.cpp: In instantiation of 'struct X<int>':
main.cpp:13:10:   required from here
main.cpp:5:34: error: cannot call member function 'void X< <template-parameter-1-1> >::foo() [with <template-parameter-1-1> = int]' without object
   auto bar() -> decltype( X::foo() )
                                  ^
main.cpp: In function 'int main()':
main.cpp:13:12: error: 'struct X<int>' has no member named 'bar'
   X<int>().bar();
            ^

Live example

当我将代码更改为 decltype( std::declval<X>().foo() ) 时GCC 对其进行编译。

这是 GCC 中的一个错误(是否有针对它的现有错误报告或应该报告它?)或者我的代码有什么问题吗?

最佳答案

关于c++ - 未评估上下文中的 "Cannot call member function ... without object"- GCC 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20312062/

相关文章:

c++ - GCC 4.8.1 C++11 是否完整?

c++ - 如何通过参数在构造函数中初始化数组?

c++ - Visual C++ 10 运行时出现奇怪的异常

c++ - 从文件中读取优先级队列 C++

c - 在特定内存中定位c库函数

c - setsid() 什么时候有用,或者为什么我们需要在 Linux 中对进程进行分组?

c++ - 在 GDB 中查看 GCC 优化中间体?

线程拼图中的c++ 11仿函数

c++ - 我该怎么做才能避免接收方出现 TCP 零窗口/TCP 窗口满?

c++ - Qt5Widgets.dll 丢失了吗?