[dcl.ambig.res] (original) (raw)
9 Declarations [dcl.dcl]
9.3 Declarators [dcl.decl]
9.3.3 Ambiguity resolution [dcl.ambig.res]
The ambiguity arising from the similarity between a function-style cast and a declaration mentioned in [stmt.ambig] can also occur in the context of a declaration.
In that context, the choice is between a function declaration with a redundant set of parentheses around a parameter name and an object declaration with a function-style cast as the initializer.
Just as for the ambiguities mentioned in [stmt.ambig], the resolution is to consider any construct that could possibly be a declaration a declaration.
[Note 1:
A declaration can be explicitly disambiguated by adding parentheses around the argument.
The ambiguity can be avoided by use of copy-initialization or list-initialization syntax, or by use of a non-function-style cast.
— _end note_]
[Example 1: struct S { S(int);};void foo(double a) { S w(int(a)); S x(int()); S y((int(a))); S y((int)a); S z = int(a); } — _end example_]
An ambiguity can arise from the similarity between a function-style cast and atype-id.
The resolution is that any construct that could possibly be atype-idin its syntactic context shall be considered atype-id.
[Example 2: template <class T> struct X {};template <int N> struct Y {}; X<int()> a; X<int(1)> b; Y<int()> c; Y<int(1)> d; void foo(signed char a) { sizeof(int()); sizeof(int(a)); sizeof(int(unsigned(a))); (int())+1; (int(a))+1; (int(unsigned(a)))+1; } — _end example_]
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 thedeclarator-id.
[Example 3: class C { };void f(int(C)) { } int g(C);void foo() { f(1); f(g); }
For another example,class C { };void h(int *(C[10]));
— _end example_]