[英]“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();
^
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中的错误吗(是否有现有的错误报告或应报告?)还是我的代码有问题?
Possibly this bug? 可能是这个错误? decltype needs explicit 'this' pointer in member function declaration of template class with trailing return type – dyp decltype在带有尾随返回类型的模板类的成员函数声明中需要显式的“ this”指针 – dyp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.