I know I'm being pedantic here, but I'm just trying to understand the C++ grammar production.
I will start with a simple-declaration.
simple-declaration:
decl-specifier-seqopt init-declarator-listopt
decl-specifier-seq:
decl-specifier
decl-specifier:
type-specifier
type-specifier:
trailing-type-specifier
trailing-type-specifier:
simple-type-specifier
simple-type-specifier:
char
int
...
auto
Now, I'll look into the definition of a init-declarator-list.
init-declarator-list:
init-declarator
init-declarator:
declarator
declarator:
noptr-declarator parameters and qualifiers trailing return type (*2)
noptr-declarator:
declarator-id attribute-specifier-seqopt
noptr-declarator parameters and qualifiers (*1)
parameters and qualifiers:
(parameter-declaration-clause) cv-qualifiersopt ... (all optionals)
trailing-return-type:
-> trailing-type-specifier-seq
trailing-type-specifier-seq:
trailing-type-specifier See the definition of a traling-type-specifier above.
Replacing noptr-declarator by a declarator-id in (*1), using the previous definition of noptr-declaration, we arrive at the following definition of nonptr-declarator:
noptr-declaration:
declarator-id parameters and qualifiers
Now replacing noptr-declarator, parameters and qualifiers and trailing-return-type in (*2) by each definition given above, we obtain the following for declarator:
declarator:
declarator-id (parameter-declaration-clause) (parameter-declaration-clause) ->
simple-type-specifier
With this last result we could say that the grammar allows the following declaration of a function f
:
auto f()() -> int;
which of course is not valid. But I couldn't find anything in the Standard saying, directly or indirectly, that this construction is ill-formed.
The error messages from GCC
(f
declared as function returning a function) and clang
(auto
return without trailing return type; deduced return types are a C++1y extensions) didn't help in this regard either.
[dcl.fct]/8:
[...] Functions shall not have a return type of type array or function, although they may have a return type of type pointer or reference to such things. [...]
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