关于规范中的§8/ 5,我需要一些帮助

Leo*_*eon 7 c++ language-lawyer trailing-return-type c++14

§8/ 5:

可选属性说明符-SEQ尾返回型 appertains所指示的返回类型.的类型ID尾返回型包括的可能的最长序列抽象声明符秒.[注意:这解决了数组和函数声明符的模糊绑定.[例如:

auto f()->int(*)[4]; // function returning a pointer to array[4] of int
                     // not function returning array[4] of pointer to int
Run Code Online (Sandbox Code Playgroud)

- 末端示例] - 尾注]

" trailing-return-type中的type-id "对我来说没有意义,只是因为trailing-return-type根据语法不包含type-id.

我也不理解数组和函数声明的"模糊绑定".据我所知

auto f() -> int*[4]; // function returning an array of 4 pointers to int
auto f() -> int(*)[4]; // function returning a pointer to an array of 4 ints  
Run Code Online (Sandbox Code Playgroud)

T.C*_*.C. 5

int *f();
Run Code Online (Sandbox Code Playgroud)

声明一个()返回指针的函数int.

int *f()[4];
Run Code Online (Sandbox Code Playgroud)

声明一个()返回4个指针数组的函数int.请注意,这是不正确的.

int (*f())[4];
Run Code Online (Sandbox Code Playgroud)

声明一个()返回指向4数组的指针的函数int.

现在,在

  auto f() -> int(*)[4]
//     ^^^^^^^^^^^^^---
Run Code Online (Sandbox Code Playgroud)

规则解析的是是否[4]trailing-return-type的一部分,因此是函数声明符的一部分.如果[4]trailing-return-type的一部分,则上面的声明声明了一个()返回指向4数组的指针的函数int.

如果没有,那么[4]将形成一个不属于函数声明符的数组声明符,并且该解析将由[dcl.array]/p1管理:

在具有表格的声明T DD

D1 [ constant-expression_opt ] attribute-specifier-seq_opt
Run Code Online (Sandbox Code Playgroud)

并且声明中标识符的类型T D1是" derived-declarator-type-list T "[...,if]常量表达式的值是N,[...]标识符的类型D是" derived-declarator" -type-list数组N T".

并且因为auto f()-> int (*)声明f为" ()返回指针的函数int",替换告诉我们这将声明一个函数返回一个包含4个指针的数组int,就像int *f()[4];.