§8/5:
The optional attribute-specifier-seq in a trailing-return-type appertains to the indicated return type. The type-id in a trailing-return-type includes the longest possible sequence of abstract-declarators. [ Note: This resolves the ambiguous binding of array and function declarators. [ Example:
auto f()->int(*)[4]; // function returning a pointer to array[4] of int // not function returning array[4] of pointer to int
—end example ] —end note ]
The "type-id in a trailing-return-type" doesn't make sense to me, simply because a trailing-return-type doesn't contain a type-id according to the grammar.
I also don't understand the "ambiguous binding" of array and function declaration. As far as I can understand
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
The most obvious difference is the size of the phones, with iPhone 8 measuring in at 4.7-inches and iPhone 8 Plus at 5.5.
Like the iPhone 7, iPhone 8 will feature a 7-megapixel front-facing FaceTime camera and a 12-megapixel rear-facing camera with an f/1.8 aperture. The rear camera system also has optical image stabilization and a 5X digital zoom.
int *f();
Declares a function of ()
returning pointer to int
.
int *f()[4];
Declares a function of ()
returning array of 4 pointers to int
. Note that this is ill-formed.
int (*f())[4];
Declares a function of ()
returning pointer to array of 4 int
.
Now, in
auto f() -> int(*)[4]
// ^^^^^^^^^^^^^---
What the rule resolves is whether [4]
is part of the trailing-return-type, and hence part of the the function declarator. If [4]
is part of the trailing-return-type, then the above declaration declares a function of ()
returning pointer to array of 4 int
.
If not, then [4]
would form an array declarator that is not part of the function declarator, and the parse would be governed by [dcl.array]/p1:
In a declaration
T D
whereD
has the formD1 [ constant-expression_opt ] attribute-specifier-seq_opt
and the type of the identifier in the declaration
T D1
is “derived-declarator-type-listT
” [..., if] the value of the constant expression isN
, [...] the type of the identifier ofD
is “derived-declarator-type-list array ofN
T
”.
and since auto f()-> int (*)
declares f
as "function of ()
returning pointer to int
", substitution tells us that this would declare a function returning an array of 4 pointers to int
, just like int *f()[4];
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With