Reputation: 68708
Consider the following C++11 code:
struct C {};
void f(int(C));
Is the type of f
the same as:
typedef int T(C);
void f(T);
or is it like:
void f(int C);
That is, should the (C)
be interpreted as a declarator
of the parameter name C
, or as an abstract-declarator
of a function parameter ?
Where is this specified in the standard?
Upvotes: 8
Views: 1099
Reputation: 507215
This is specified in 8.2p7
7 Another ambiguity arises in a parameter-declaration-clause of a function declaration, or in a type-id that is the operand of a sizeof or typeid operator, when a type-name is nested in parentheses. In this case, the choice is between the declaration of a parameter of type pointer to function and the declaration of a parameter with redundant parentheses around the declarator-id. The resolution is to consider the type-name as a simple-type-specifier rather than a declarator-id.
Hence, your parameter has type int(*)(C)
, as you show in your first possible interpretation.
Upvotes: 12