tmp/tmpq7t3uso4/{from.md → to.md}
RENAMED
|
@@ -5,15 +5,20 @@ and *declaration*s: An *expression-statement* with a function-style
|
|
| 5 |
explicit type conversion ([[expr.type.conv]]) as its leftmost
|
| 6 |
subexpression can be indistinguishable from a *declaration* where the
|
| 7 |
first *declarator* starts with a `(`. In those cases the *statement* is
|
| 8 |
a *declaration*.
|
| 9 |
|
|
|
|
|
|
|
| 10 |
If the *statement* cannot syntactically be a *declaration*, there is no
|
| 11 |
ambiguity, so this rule does not apply. The whole *statement* might need
|
| 12 |
to be examined to determine whether this is the case. This resolves the
|
| 13 |
-
meaning of many examples.
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
``` cpp
|
| 17 |
T(a)->m = 7; // expression-statement
|
| 18 |
T(a)++; // expression-statement
|
| 19 |
T(a,5)<<c; // expression-statement
|
|
@@ -26,12 +31,16 @@ T(*g)(double(3)); // declaration
|
|
| 26 |
|
| 27 |
In the last example above, `g`, which is a pointer to `T`, is
|
| 28 |
initialized to `double(3)`. This is of course ill-formed for semantic
|
| 29 |
reasons, but that does not affect the syntactic analysis.
|
| 30 |
|
|
|
|
|
|
|
| 31 |
The remaining cases are *declaration*s.
|
| 32 |
|
|
|
|
|
|
|
| 33 |
``` cpp
|
| 34 |
class T {
|
| 35 |
// ...
|
| 36 |
public:
|
| 37 |
T();
|
|
@@ -44,20 +53,28 @@ T(c)=7; // declaration
|
|
| 44 |
T(d),e,f=3; // declaration
|
| 45 |
extern int h;
|
| 46 |
T(g)(h,2); // declaration
|
| 47 |
```
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
The disambiguation is purely syntactic; that is, the meaning of the
|
| 50 |
names occurring in such a statement, beyond whether they are
|
| 51 |
*type-name*s or not, is not generally used in or changed by the
|
| 52 |
disambiguation. Class templates are instantiated as necessary to
|
| 53 |
determine if a qualified name is a *type-name*. Disambiguation precedes
|
| 54 |
parsing, and a statement disambiguated as a declaration may be an
|
| 55 |
ill-formed declaration. If, during parsing, a name in a template
|
| 56 |
parameter is bound differently than it would be bound during a trial
|
| 57 |
-
parse, the program is ill-formed. No diagnostic is required.
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
``` cpp
|
| 61 |
struct T1 {
|
| 62 |
T1 operator()(int x) { return T1(x); }
|
| 63 |
int operator=(int x) { return x; }
|
|
@@ -67,27 +84,26 @@ struct T2 { T2(int){ } };
|
|
| 67 |
int a, (*(*b)(T2))(int), c, d;
|
| 68 |
|
| 69 |
void f() {
|
| 70 |
// disambiguation requires this to be parsed as a declaration:
|
| 71 |
T1(a) = 3,
|
| 72 |
-
T2(4), // T2 will be declared as
|
| 73 |
-
(*(*b)(T2(c)))(int(d)); //
|
| 74 |
-
//
|
| 75 |
-
// the last part of the
|
| 76 |
-
// declaration to parse
|
| 77 |
-
// properly since it depends
|
| 78 |
-
// on T2 being a type-name
|
| 79 |
}
|
| 80 |
```
|
| 81 |
|
|
|
|
|
|
|
| 82 |
<!-- Link reference definitions -->
|
|
|
|
| 83 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 84 |
[basic.lookup.classref]: basic.md#basic.lookup.classref
|
| 85 |
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 86 |
[basic.scope]: basic.md#basic.scope
|
| 87 |
[basic.scope.pdecl]: basic.md#basic.scope.pdecl
|
| 88 |
-
[basic.start.
|
| 89 |
[basic.start.term]: basic.md#basic.start.term
|
| 90 |
[basic.stc.auto]: basic.md#basic.stc.auto
|
| 91 |
[basic.stc.static]: basic.md#basic.stc.static
|
| 92 |
[basic.stc.thread]: basic.md#basic.stc.thread
|
| 93 |
[class.copy]: special.md#class.copy
|
|
@@ -95,11 +111,10 @@ void f() {
|
|
| 95 |
[class.dtor]: special.md#class.dtor
|
| 96 |
[class.temporary]: special.md#class.temporary
|
| 97 |
[conv]: conv.md#conv
|
| 98 |
[conv.prom]: conv.md#conv.prom
|
| 99 |
[dcl.init]: dcl.md#dcl.init
|
| 100 |
-
[dcl.init.list]: dcl.md#dcl.init.list
|
| 101 |
[dcl.meaning]: dcl.md#dcl.meaning
|
| 102 |
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 103 |
[dcl.type]: dcl.md#dcl.type
|
| 104 |
[expr]: expr.md#expr
|
| 105 |
[expr.const]: expr.md#expr.const
|
|
@@ -122,18 +137,17 @@ void f() {
|
|
| 122 |
[stmt.select]: #stmt.select
|
| 123 |
[stmt.stmt]: #stmt.stmt
|
| 124 |
[stmt.switch]: #stmt.switch
|
| 125 |
[stmt.while]: #stmt.while
|
| 126 |
[support.start.term]: language.md#support.start.term
|
|
|
|
| 127 |
|
| 128 |
[^1]: In other words, the `else` is associated with the nearest un-elsed
|
| 129 |
`if`.
|
| 130 |
|
| 131 |
-
[^2]:
|
| 132 |
-
reinterpreted as a delimiter between *init-declarator*s in the
|
| 133 |
-
declaration of `__range`.
|
| 134 |
-
|
| 135 |
-
[^3]: The transfer from the condition of a `switch` statement to a
|
| 136 |
`case` label is considered a jump in this respect.
|
| 137 |
|
| 138 |
-
[^
|
| 139 |
-
execution of the initializer.
|
|
|
|
|
|
|
|
|
| 5 |
explicit type conversion ([[expr.type.conv]]) as its leftmost
|
| 6 |
subexpression can be indistinguishable from a *declaration* where the
|
| 7 |
first *declarator* starts with a `(`. In those cases the *statement* is
|
| 8 |
a *declaration*.
|
| 9 |
|
| 10 |
+
[*Note 1*:
|
| 11 |
+
|
| 12 |
If the *statement* cannot syntactically be a *declaration*, there is no
|
| 13 |
ambiguity, so this rule does not apply. The whole *statement* might need
|
| 14 |
to be examined to determine whether this is the case. This resolves the
|
| 15 |
+
meaning of many examples.
|
| 16 |
+
|
| 17 |
+
[*Example 1*:
|
| 18 |
+
|
| 19 |
+
Assuming `T` is a *simple-type-specifier* ([[dcl.type]]),
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
T(a)->m = 7; // expression-statement
|
| 23 |
T(a)++; // expression-statement
|
| 24 |
T(a,5)<<c; // expression-statement
|
|
|
|
| 31 |
|
| 32 |
In the last example above, `g`, which is a pointer to `T`, is
|
| 33 |
initialized to `double(3)`. This is of course ill-formed for semantic
|
| 34 |
reasons, but that does not affect the syntactic analysis.
|
| 35 |
|
| 36 |
+
— *end example*]
|
| 37 |
+
|
| 38 |
The remaining cases are *declaration*s.
|
| 39 |
|
| 40 |
+
[*Example 2*:
|
| 41 |
+
|
| 42 |
``` cpp
|
| 43 |
class T {
|
| 44 |
// ...
|
| 45 |
public:
|
| 46 |
T();
|
|
|
|
| 53 |
T(d),e,f=3; // declaration
|
| 54 |
extern int h;
|
| 55 |
T(g)(h,2); // declaration
|
| 56 |
```
|
| 57 |
|
| 58 |
+
— *end example*]
|
| 59 |
+
|
| 60 |
+
— *end note*]
|
| 61 |
+
|
| 62 |
The disambiguation is purely syntactic; that is, the meaning of the
|
| 63 |
names occurring in such a statement, beyond whether they are
|
| 64 |
*type-name*s or not, is not generally used in or changed by the
|
| 65 |
disambiguation. Class templates are instantiated as necessary to
|
| 66 |
determine if a qualified name is a *type-name*. Disambiguation precedes
|
| 67 |
parsing, and a statement disambiguated as a declaration may be an
|
| 68 |
ill-formed declaration. If, during parsing, a name in a template
|
| 69 |
parameter is bound differently than it would be bound during a trial
|
| 70 |
+
parse, the program is ill-formed. No diagnostic is required.
|
| 71 |
+
|
| 72 |
+
[*Note 2*: This can occur only when the name is declared earlier in the
|
| 73 |
+
declaration. — *end note*]
|
| 74 |
+
|
| 75 |
+
[*Example 3*:
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
struct T1 {
|
| 79 |
T1 operator()(int x) { return T1(x); }
|
| 80 |
int operator=(int x) { return x; }
|
|
|
|
| 84 |
int a, (*(*b)(T2))(int), c, d;
|
| 85 |
|
| 86 |
void f() {
|
| 87 |
// disambiguation requires this to be parsed as a declaration:
|
| 88 |
T1(a) = 3,
|
| 89 |
+
T2(4), // T2 will be declared as a variable of type T1, but this will not
|
| 90 |
+
(*(*b)(T2(c)))(int(d)); // allow the last part of the declaration to parse properly,
|
| 91 |
+
// since it depends on T2 being a type-name
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
```
|
| 94 |
|
| 95 |
+
— *end example*]
|
| 96 |
+
|
| 97 |
<!-- Link reference definitions -->
|
| 98 |
+
[basic.def.odr]: basic.md#basic.def.odr
|
| 99 |
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 100 |
[basic.lookup.classref]: basic.md#basic.lookup.classref
|
| 101 |
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 102 |
[basic.scope]: basic.md#basic.scope
|
| 103 |
[basic.scope.pdecl]: basic.md#basic.scope.pdecl
|
| 104 |
+
[basic.start.main]: basic.md#basic.start.main
|
| 105 |
[basic.start.term]: basic.md#basic.start.term
|
| 106 |
[basic.stc.auto]: basic.md#basic.stc.auto
|
| 107 |
[basic.stc.static]: basic.md#basic.stc.static
|
| 108 |
[basic.stc.thread]: basic.md#basic.stc.thread
|
| 109 |
[class.copy]: special.md#class.copy
|
|
|
|
| 111 |
[class.dtor]: special.md#class.dtor
|
| 112 |
[class.temporary]: special.md#class.temporary
|
| 113 |
[conv]: conv.md#conv
|
| 114 |
[conv.prom]: conv.md#conv.prom
|
| 115 |
[dcl.init]: dcl.md#dcl.init
|
|
|
|
| 116 |
[dcl.meaning]: dcl.md#dcl.meaning
|
| 117 |
[dcl.spec.auto]: dcl.md#dcl.spec.auto
|
| 118 |
[dcl.type]: dcl.md#dcl.type
|
| 119 |
[expr]: expr.md#expr
|
| 120 |
[expr.const]: expr.md#expr.const
|
|
|
|
| 137 |
[stmt.select]: #stmt.select
|
| 138 |
[stmt.stmt]: #stmt.stmt
|
| 139 |
[stmt.switch]: #stmt.switch
|
| 140 |
[stmt.while]: #stmt.while
|
| 141 |
[support.start.term]: language.md#support.start.term
|
| 142 |
+
[temp]: temp.md#temp
|
| 143 |
|
| 144 |
[^1]: In other words, the `else` is associated with the nearest un-elsed
|
| 145 |
`if`.
|
| 146 |
|
| 147 |
+
[^2]: The transfer from the condition of a `switch` statement to a
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
`case` label is considered a jump in this respect.
|
| 149 |
|
| 150 |
+
[^3]: The implementation must not introduce any deadlock around
|
| 151 |
+
execution of the initializer. Deadlocks might still be caused by the
|
| 152 |
+
program logic; the implementation need only avoid deadlocks due to
|
| 153 |
+
its own synchronization operations.
|