trailing-return-type中的占位符是否会覆盖初始占位符?

eca*_*mur 6 c++ decltype trailing-return-type return-type-deduction c++14

克++出现接受的任何组合autodecltype(auto)作为初始和结尾返回类型:

int a;
auto f() { return (a); }                             // int
auto g() -> auto { return (a); }                     // int
auto h() -> decltype(auto) { return (a); }           // int&
decltype(auto) i() { return (a); }                   // int&
decltype(auto) j() -> auto { return (a); }           // int
decltype(auto) k() -> decltype(auto) { return (a); } // int&
Run Code Online (Sandbox Code Playgroud)

但是,clang拒绝j并且k说:error:具有尾随返回类型的函数必须指定返回类型'auto',而不是'decltype(auto)'(演示).

哪个编译器正确?在每种情况下应该使用哪个规则(autodecltype(auto))?在尾随返回类型中使用占位符类型是否有意义?

Xeo*_*Xeo 14

auto在引入尾随返回类型时需要.

§8.3.5[dcl.fct]/2

在具有表格的声明T DD

D1 ( parameter-declaration-clause)cv-qualifier-seqopt ref-qualifieropt exception-specificationopt attribute-specifier-seqopt trailing-return-type

和包含的类型说明符-ID的声明T D1是"derived- 声明符类型列表 T ",

T应该是单一类型说明符 auto.[...]

另见核心问题1852,与[dcl.spec.auto]/1明显矛盾.