以下程序可以使用 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();
^
实例 http://coliru.stacked-crooked.com/a/307f5bfa29ab8d45
当我将代码更改为decltype( std::declval<X>().foo() )
GCC 编译它。
这是 GCC 中的错误吗(是否有现有的错误报告或应该报告它?)或者我的代码有什么问题吗?
可能是这个bug?decltype 需要在具有尾随返回类型的模板类的成员函数声明中显式“this”指针 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57543 – dyp
Fixed. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57543#c8
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)