简体   繁体   English

未评估的上下文中的“无法调用成员函数…没有对象”-GCC错误?

[英]“Cannot call member function … without object” inside unevaluated context - GCC bug?

The following program compiles fine with Clang: 以下程序可以使用Clang进行编译:

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

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

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

But GCC 4.8.1 gives: 但是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 现场例子

When I change the code to decltype( std::declval<X>().foo() ) GCC compiles it. 当我将代码更改为decltype( std::declval<X>().foo() ) GCC会对其进行编译。

Is this a bug in GCC (and is there an existing bug report for it or should report it?) or is there anything wrong with my code? 这是GCC中的错误吗(是否有现有的错误报告或应报告?)还是我的代码有问题?

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

相关问题 没有对象错误就无法调用成员函数 - cannot call member function without object error 命名空间:不能在没有对象的情况下调用成员函数 - namespace: cannot call member function without object 不能调用没有 object 的成员 function - cannot call member function without object 有没有理由我们无法在未评估的上下文中命名非静态成员函数? - Is there a reason we cannot name a non-static member function in an unevaluated context? 没有对象就无法调用成员函数,但是我有一个对象才能调用该函数 - Cannot call member function without object but I call the function with an object 没有对象就无法调用成员函数std :: string class :: function() - Cannot call member function std::string class::function() without object 在静态成员函数中未评估的上下文中 - this in unevaluated context in static member functions 错误:没有 object 无法呼叫成员 function - 但我有一个 object? - error: cannot call member function without object - but I have an object? 错误:在没有对象的情况下无法调用成员函数&#39;void Fortest :: run()&#39; - error: cannot call member function 'void Fortest::run()' without object| Qt C ++无法在没有对象的情况下调用成员函数“” - Qt C++ cannot call member function ' ' without object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM