tmp/tmpgy0k9wif/{from.md → to.md}
RENAMED
|
@@ -6,11 +6,14 @@ context of a declaration. In that context, the choice is between an
|
|
| 6 |
object declaration with a function-style cast as the initializer and a
|
| 7 |
declaration involving a function declarator with a redundant set of
|
| 8 |
parentheses around a parameter name. Just as for the ambiguities
|
| 9 |
mentioned in [[stmt.ambig]], the resolution is to consider any
|
| 10 |
construct, such as the potential parameter declaration, that could
|
| 11 |
-
possibly be a declaration to be a declaration.
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
[*Note 1*: A declaration can be explicitly disambiguated by adding
|
| 14 |
parentheses around the argument. The ambiguity can be avoided by use of
|
| 15 |
copy-initialization or list-initialization syntax, or by use of a
|
| 16 |
non-function-style cast. — *end note*]
|
|
@@ -19,26 +22,32 @@ non-function-style cast. — *end note*]
|
|
| 19 |
|
| 20 |
``` cpp
|
| 21 |
struct S {
|
| 22 |
S(int);
|
| 23 |
};
|
|
|
|
| 24 |
|
| 25 |
void foo(double a) {
|
| 26 |
-
S
|
| 27 |
-
S
|
| 28 |
-
S
|
| 29 |
S y((int)a); // object declaration
|
| 30 |
S z = int(a); // object declaration
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
```
|
| 33 |
|
| 34 |
— *end example*]
|
| 35 |
|
| 36 |
An ambiguity can arise from the similarity between a function-style cast
|
| 37 |
and a *type-id*. The resolution is that any construct that could
|
| 38 |
possibly be a *type-id* in its syntactic context shall be considered a
|
| 39 |
-
*type-id*.
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
[*Example 2*:
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
template <class T> struct X {};
|
|
@@ -55,10 +64,16 @@ void foo(signed char a) {
|
|
| 55 |
|
| 56 |
(int())+1; // type-id (ill-formed)
|
| 57 |
(int(a))+1; // expression
|
| 58 |
(int(unsigned(a)))+1; // type-id (ill-formed)
|
| 59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
```
|
| 61 |
|
| 62 |
— *end example*]
|
| 63 |
|
| 64 |
Another ambiguity arises in a *parameter-declaration-clause* when a
|
|
|
|
| 6 |
object declaration with a function-style cast as the initializer and a
|
| 7 |
declaration involving a function declarator with a redundant set of
|
| 8 |
parentheses around a parameter name. Just as for the ambiguities
|
| 9 |
mentioned in [[stmt.ambig]], the resolution is to consider any
|
| 10 |
construct, such as the potential parameter declaration, that could
|
| 11 |
+
possibly be a declaration to be a declaration. However, a construct that
|
| 12 |
+
can syntactically be a *declaration* whose outermost *declarator* would
|
| 13 |
+
match the grammar of a *declarator* with a *trailing-return-type* is a
|
| 14 |
+
declaration only if it starts with `auto`.
|
| 15 |
|
| 16 |
[*Note 1*: A declaration can be explicitly disambiguated by adding
|
| 17 |
parentheses around the argument. The ambiguity can be avoided by use of
|
| 18 |
copy-initialization or list-initialization syntax, or by use of a
|
| 19 |
non-function-style cast. — *end note*]
|
|
|
|
| 22 |
|
| 23 |
``` cpp
|
| 24 |
struct S {
|
| 25 |
S(int);
|
| 26 |
};
|
| 27 |
+
typedef struct BB { int C[2]; } *B, C;
|
| 28 |
|
| 29 |
void foo(double a) {
|
| 30 |
+
S v(int(a)); // function declaration
|
| 31 |
+
S w(int()); // function declaration
|
| 32 |
+
S x((int(a))); // object declaration
|
| 33 |
S y((int)a); // object declaration
|
| 34 |
S z = int(a); // object declaration
|
| 35 |
+
S a(B()->C); // object declaration
|
| 36 |
+
S b(auto()->C); // function declaration
|
| 37 |
}
|
| 38 |
```
|
| 39 |
|
| 40 |
— *end example*]
|
| 41 |
|
| 42 |
An ambiguity can arise from the similarity between a function-style cast
|
| 43 |
and a *type-id*. The resolution is that any construct that could
|
| 44 |
possibly be a *type-id* in its syntactic context shall be considered a
|
| 45 |
+
*type-id*. However, a construct that can syntactically be a *type-id*
|
| 46 |
+
whose outermost *abstract-declarator* would match the grammar of an
|
| 47 |
+
*abstract-declarator* with a *trailing-return-type* is considered a
|
| 48 |
+
*type-id* only if it starts with `auto`.
|
| 49 |
|
| 50 |
[*Example 2*:
|
| 51 |
|
| 52 |
``` cpp
|
| 53 |
template <class T> struct X {};
|
|
|
|
| 64 |
|
| 65 |
(int())+1; // type-id (ill-formed)
|
| 66 |
(int(a))+1; // expression
|
| 67 |
(int(unsigned(a)))+1; // type-id (ill-formed)
|
| 68 |
}
|
| 69 |
+
|
| 70 |
+
typedef struct BB { int C[2]; } *B, C;
|
| 71 |
+
void g() {
|
| 72 |
+
sizeof(B()->C[1]); // OK, sizeof(expression)
|
| 73 |
+
sizeof(auto()->C[1]); // error: sizeof of a function returning an array
|
| 74 |
+
}
|
| 75 |
```
|
| 76 |
|
| 77 |
— *end example*]
|
| 78 |
|
| 79 |
Another ambiguity arises in a *parameter-declaration-clause* when a
|