8

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?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319

1 Answers1

12

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.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212