我遇到了这段包含尾随返回类型和继承的代码片段。
以下最小示例可以使用g ++而不是clang进行编译
struct Base {};
int foo(Base&) {
return 42;
}
struct Derived : public Base {
auto bar() -> decltype(foo(*this)) {
return foo(*this);
}
};
int main()
{
Derived derived;
derived.bar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我们更改auto bar() -> decltype(foo(*this))为decltype(auto) bar()(c ++ 14扩展名),代码也会使用clang进行编译。链接到Godbolt https://godbolt.org/z/qf_k6X。
谁能解释我
auto bar() -> decltype(return expression)不同decltype(auto) bar()