Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 ambiguity between declarator and abstract-declarator in parameter clause?

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?

like image 663
Andrew Tomazos Avatar asked Jun 25 '13 15:06

Andrew Tomazos


1 Answers

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.

like image 116
Johannes Schaub - litb Avatar answered Sep 27 '22 21:09

Johannes Schaub - litb