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
an object declaration
with a function-style cast as the initializer and
a declaration involving a function declarator
with a redundant set of parentheses around a parameter name
. Just as for the ambiguities mentioned in
[stmt.ambig],
the resolution is to consider any construct,
such as the potential parameter declaration,
that could possibly be a declaration
to be 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]