[英]“Cannot call member function … without object” inside unevaluated context - GCC bug?
以下程序可以使用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();
^
当我将代码更改为decltype( std::declval<X>().foo() )
GCC会对其进行编译。
这是GCC中的错误吗(是否有现有的错误报告或应报告?)还是我的代码有问题?
可能是这个错误? decltype在带有尾随返回类型的模板类的成员函数声明中需要显式的“ this”指针 – dyp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.