Otherwise (auto appearing with no type specifiers other
than cv-qualifiers), the auto type-specifier
signifies that the type of an object being declared shall be deduced from
its initializer or specified explicitly at the end of a function
declarator. The name of the object being declared shall not appear
in the initializer expression.
auto can appear with a function declarator with a late-specified return type (8.3.5) in any context where such a declarator is valid, and the use of auto is replaced by the type specified at the end of the declarator.
Otherwise, the type of the object is deduced from its initializer. The name of the object being declared shall not appear in the initializer expression. This use of auto is allowed when declaring objects in a block (6.3), in namespace scope (3.3.5), and in a for-init-statement (6.5.3). [...]
direct-declarator: declarator-id direct-declarator ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt exception-specificationopt direct-declarator ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt exception-specificationopt -> type-id direct-declarator [ constant-expressionopt ] ( declarator )
direct-abstract-declarator: direct-abstract-declaratoropt ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt exception-specificationopt direct-abstract-declaratoropt ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt exception-specificationopt -> type-id direct-abstract-declaratoropt [ constant-expressionopt ] ( abstract-declarator )
In a declaration T D where D has the form
and the type of the contained declarator-id in the declaration T D1 is "derived-declarator-type-list T," the type of the declarator-id in D is "derived-declarator-type-list function of (parameter-declaration-clause) cv-qualifier-seqopt ref-qualifieropt returning T"D1 ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt exception-specificationopt
In a declaration T D where D has the form
and the type of the contained declarator-id in the declaration
T D1 is "derived-declarator-type-list T,"
T shall be the single type-specifier auto and
the derived-declarator-type-list shall be empty.
Then the type of the declarator-id in D is "function of
(parameter-declaration-clause) cv-qualifier-seqopt
ref-qualifieropt
returning type-id".
Such a function type has a late-specified return type.
D1 ( parameter-declaration-clause ) cv-qualifier-seqopt ref-qualifieropt exception-specificationopt -> type-id
The type-id in this form 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]
A type of either form is a function type*.
[Footnote: As indicated by the syntax, cv-qualifiers are a significant component in function return types. --- end foonote]
typedef int IFUNC(int); IFUNC* fpif(int);or
auto fpif(int)->int(*)(int)A late-specified return type is most useful for a type that would be more complicated to specify before the declarator-id:
template <class T, class U> auto add(T t, U u) -> decltype(t+u);rather than
template <class T, class U> decltype((*(T*)0)+(*(U*)0)) add(T t, U u);-- end note ]