Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top