From Jason Turner

[stmt.ambig]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp_a3riu0q/{from.md → to.md} +51 -5
tmp/tmp_a3riu0q/{from.md → to.md} RENAMED
@@ -3,22 +3,22 @@
3
  There is an ambiguity in the grammar involving *expression-statement*s
4
  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
  [*Note 1*:
11
 
12
  If the *statement* cannot syntactically be a *declaration*, there is no
13
  ambiguity, so this rule does not apply. In some cases, the whole
14
  *statement* needs to be examined to determine whether this is the case.
15
  This resolves the 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
@@ -89,11 +89,47 @@ void f() {
89
  }
90
  ```
91
 
92
  — *end example*]
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  <!-- Link reference definitions -->
 
 
 
95
  [basic.life]: basic.md#basic.life
96
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
97
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
98
  [basic.scope]: basic.md#basic.scope
99
  [basic.scope.block]: basic.md#basic.scope.block
@@ -107,27 +143,36 @@ void f() {
107
  [class.dtor]: class.md#class.dtor
108
  [class.member.lookup]: basic.md#class.member.lookup
109
  [class.temporary]: basic.md#class.temporary
110
  [conv]: expr.md#conv
111
  [conv.prom]: expr.md#conv.prom
112
- [dcl.dcl]: dcl.md#dcl.dcl
 
113
  [dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
114
  [dcl.init]: dcl.md#dcl.init
115
  [dcl.meaning]: dcl.md#dcl.meaning
 
116
  [dcl.spec.auto]: dcl.md#dcl.spec.auto
117
- [dcl.type]: dcl.md#dcl.type
 
118
  [except.ctor]: except.md#except.ctor
119
  [expr.await]: expr.md#expr.await
 
120
  [expr.const]: expr.md#expr.const
121
  [expr.context]: expr.md#expr.context
122
  [expr.type.conv]: expr.md#expr.type.conv
 
 
 
123
  [stmt.ambig]: #stmt.ambig
124
  [stmt.block]: #stmt.block
125
  [stmt.break]: #stmt.break
126
  [stmt.cont]: #stmt.cont
 
127
  [stmt.dcl]: #stmt.dcl
128
  [stmt.do]: #stmt.do
 
129
  [stmt.expr]: #stmt.expr
130
  [stmt.for]: #stmt.for
131
  [stmt.goto]: #stmt.goto
132
  [stmt.if]: #stmt.if
133
  [stmt.iter]: #stmt.iter
@@ -139,16 +184,17 @@ void f() {
139
  [stmt.ranged]: #stmt.ranged
140
  [stmt.return]: #stmt.return
141
  [stmt.return.coroutine]: #stmt.return.coroutine
142
  [stmt.select]: #stmt.select
143
  [stmt.select.general]: #stmt.select.general
144
- [stmt.stmt]: #stmt.stmt
145
  [stmt.switch]: #stmt.switch
146
  [stmt.while]: #stmt.while
147
  [support.start.term]: support.md#support.start.term
 
148
  [temp.pre]: temp.md#temp.pre
149
  [term.odr.use]: basic.md#term.odr.use
 
150
 
151
  [^1]: In other words, the `else` is associated with the nearest un-elsed
152
  `if`.
153
 
154
  [^2]: The transfer from the condition of a `switch` statement to a
 
3
  There is an ambiguity in the grammar involving *expression-statement*s
4
  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
+ considered a *declaration*, except as specified below.
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. In some cases, the whole
14
  *statement* needs to be examined to determine whether this is the case.
15
  This resolves the meaning of many examples.
16
 
17
  [*Example 1*:
18
 
19
+ Assuming `T` is a *simple-type-specifier* [[dcl.type.simple]],
20
 
21
  ``` cpp
22
  T(a)->m = 7; // expression-statement
23
  T(a)++; // expression-statement
24
  T(a,5)<<c; // expression-statement
 
89
  }
90
  ```
91
 
92
  — *end example*]
93
 
94
+ A syntactically ambiguous statement that can syntactically be a
95
+ *declaration* with an outermost *declarator* with a
96
+ *trailing-return-type* is considered a *declaration* only if it starts
97
+ with `auto`.
98
+
99
+ [*Example 4*:
100
+
101
+ ``` cpp
102
+ struct M;
103
+ struct S {
104
+ S* operator()();
105
+ int N;
106
+ int M;
107
+
108
+ void mem(S s) {
109
+ auto(s)()->M; // expression, S::M hides ::M
110
+ }
111
+ };
112
+
113
+ void f(S s) {
114
+ {
115
+ auto(s)()->N; // expression
116
+ auto(s)()->M; // function declaration
117
+ }
118
+ {
119
+ S(s)()->N; // expression
120
+ S(s)()->M; // expression
121
+ }
122
+ }
123
+ ```
124
+
125
+ — *end example*]
126
+
127
  <!-- Link reference definitions -->
128
+ [basic.contract]: basic.md#basic.contract
129
+ [basic.contract.eval]: basic.md#basic.contract.eval
130
+ [basic.contract.general]: basic.md#basic.contract.general
131
  [basic.life]: basic.md#basic.life
132
  [basic.lookup.argdep]: basic.md#basic.lookup.argdep
133
  [basic.lookup.unqual]: basic.md#basic.lookup.unqual
134
  [basic.scope]: basic.md#basic.scope
135
  [basic.scope.block]: basic.md#basic.scope.block
 
143
  [class.dtor]: class.md#class.dtor
144
  [class.member.lookup]: basic.md#class.member.lookup
145
  [class.temporary]: basic.md#class.temporary
146
  [conv]: expr.md#conv
147
  [conv.prom]: expr.md#conv.prom
148
+ [dcl]: dcl.md#dcl
149
+ [dcl.contract.func]: dcl.md#dcl.contract.func
150
  [dcl.fct.def.coroutine]: dcl.md#dcl.fct.def.coroutine
151
  [dcl.init]: dcl.md#dcl.init
152
  [dcl.meaning]: dcl.md#dcl.meaning
153
+ [dcl.pre]: dcl.md#dcl.pre
154
  [dcl.spec.auto]: dcl.md#dcl.spec.auto
155
+ [dcl.struct.bind]: dcl.md#dcl.struct.bind
156
+ [dcl.type.simple]: dcl.md#dcl.type.simple
157
  [except.ctor]: except.md#except.ctor
158
  [expr.await]: expr.md#expr.await
159
+ [expr.call]: expr.md#expr.call
160
  [expr.const]: expr.md#expr.const
161
  [expr.context]: expr.md#expr.context
162
  [expr.type.conv]: expr.md#expr.type.conv
163
+ [intro.execution]: basic.md#intro.execution
164
+ [meta.rel]: meta.md#meta.rel
165
+ [stmt]: #stmt
166
  [stmt.ambig]: #stmt.ambig
167
  [stmt.block]: #stmt.block
168
  [stmt.break]: #stmt.break
169
  [stmt.cont]: #stmt.cont
170
+ [stmt.contract.assert]: #stmt.contract.assert
171
  [stmt.dcl]: #stmt.dcl
172
  [stmt.do]: #stmt.do
173
+ [stmt.expand]: #stmt.expand
174
  [stmt.expr]: #stmt.expr
175
  [stmt.for]: #stmt.for
176
  [stmt.goto]: #stmt.goto
177
  [stmt.if]: #stmt.if
178
  [stmt.iter]: #stmt.iter
 
184
  [stmt.ranged]: #stmt.ranged
185
  [stmt.return]: #stmt.return
186
  [stmt.return.coroutine]: #stmt.return.coroutine
187
  [stmt.select]: #stmt.select
188
  [stmt.select.general]: #stmt.select.general
 
189
  [stmt.switch]: #stmt.switch
190
  [stmt.while]: #stmt.while
191
  [support.start.term]: support.md#support.start.term
192
+ [temp.decls.general]: temp.md#temp.decls.general
193
  [temp.pre]: temp.md#temp.pre
194
  [term.odr.use]: basic.md#term.odr.use
195
+ [thread.thread.this]: thread.md#thread.thread.this
196
 
197
  [^1]: In other words, the `else` is associated with the nearest un-elsed
198
  `if`.
199
 
200
  [^2]: The transfer from the condition of a `switch` statement to a