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]