eca*_*mur 6 c++ decltype trailing-return-type return-type-deduction c++14
克++出现接受的任何组合auto和decltype(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)'(演示).
哪个编译器正确?在每种情况下应该使用哪个规则(auto或decltype(auto))?在尾随返回类型中使用占位符类型是否有意义?
Xeo*_*Xeo 14
auto在引入尾随返回类型时需要.
§8.3.5[dcl.fct]/2
在具有表格的声明
T D中D
D1 (parameter-declaration-clause)cv-qualifier-seqoptref-qualifieroptexception-specificationoptattribute-specifier-seqopttrailing-return-type和包含的类型说明符-ID的声明
T D1是"derived- 声明符类型列表T",
T应该是单一类型说明符 auto.[...]
另见核心问题1852,与[dcl.spec.auto]/1明显矛盾.
| 归档时间: |
|
| 查看次数: |
348 次 |
| 最近记录: |