Skip to content

Commit 66d0edd

Browse files
BolpatQuirin Schroll
andauthored
Rephrase IfCondition variables (#3886)
Co-authored-by: Quirin Schroll <[email protected]>
1 parent 8e3a883 commit 66d0edd

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

spec/statement.dd

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,14 @@ $(GNAME ElseStatement):
262262
$(P If there is a declared *Identifier* variable,
263263
$(RELATIVE_LINK2 condition-variables, it is evaluated).
264264
Otherwise, *Expression* is evaluated. The result is converted to a
265-
boolean.
266-
If the boolean is `true`, the $(I ThenStatement) is transferred
265+
boolean.)
266+
267+
$(P If the boolean is `true`, the $(I ThenStatement) is transferred
267268
to, otherwise the $(I ElseStatement) is transferred to.)
268269

269270
$(P The $(I ElseStatement) is associated with the innermost `if`
270271
statement which does not already have an associated $(I ElseStatement).)
271272

272-
$(P If both, `auto` and `ref` are present, the variable is a reference
273-
if and only if the *Expression* is an lvalue.)
274-
275273
$(H3 $(LNAME2 boolean-conditions, Boolean Conversion))
276274

277275
$(P The following type instances are supported in a condition:)
@@ -296,18 +294,28 @@ $(H3 $(LNAME2 condition-variables, Condition Variables))
296294
$(P
297295
When an $(I Identifier) form of *IfCondition* is used, a
298296
variable is declared with that name and initialized to the
299-
value of the *Expression*.
297+
value of the $(I Expression).
300298
)
301299

302-
* If $(D auto) $(I Identifier) is provided, the type of the variable
303-
is the same as *Expression*.
300+
* If both `auto` and `ref` are present among $(I IfConditionStorageClasses),
301+
the variable is a reference
302+
if and only if the $(I Expression) is an lvalue;
303+
304+
* If `ref` is present without `auto`,
305+
the variable is a reference and $(I Expression) must be an lvalue.
304306

305-
* If $(I TypeCtors) $(I Identifier) is provided, the variable is
306-
declared to be the type of *Expression* but with $(I TypeCtors) applied.
307+
* If `auto` is present without `ref`, the type of the variable
308+
is the same as $(I Expression).
309+
The presence of `auto` in combination with any $(I IfConditionStorageClasses)
310+
except `ref` (cf. first bullet point)
311+
has no effect.
312+
Only if no other $(I IfConditionStorageClasses) are meaningful,
313+
`auto` provides an option to declare a variable.
314+
Using `auto` without `ref` when $(I BasicType) is given is not allowed.
307315

308-
* If the $(I BasicType) form is provided, it declares the type of the
309-
variable as it would for a normal
310-
$(DDSUBLINK spec/declaration, variable-declarations, variable declaration).
316+
* If $(I TypeCtors) are provided and possibly the $(I BasicType) is given,
317+
the variable is declared as it would for a normal
318+
$(DDSUBLINK spec/declaration, variable-declarations, variable declaration).
311319

312320
$(P The scope of the variable is the *ThenStatement* only.)
313321

@@ -357,18 +365,7 @@ while (i < 10)
357365
}
358366
---
359367

360-
$(P If an $(D auto) $(I Identifier) is provided, it is declared and
361-
initialized to the value and type of the *Expression*. Its scope
362-
extends from when it is initialized to the end of the *ScopeStatement*.)
363-
364-
$(P If a $(I TypeCtors) $(I Identifier) is provided, it is declared
365-
to be of the type specified by $(I TypeCtors) and is initialized with
366-
the value of the *Expression*. Its scope extends from when it is
367-
initialized to the end of the *ScopeStatement*.)
368-
369-
$(P If a $(I Declarator) is provided, it is declared and initialized
370-
to the value of the *Expression*. Its scope extends from when it is
371-
initialized to the end of the *ScopeStatement*.)
368+
$(P If the $(I IfCondition) declares a variable, $(RELATIVE_LINK2 condition-variables, it is initialized and evaluated) on every loop iteration.)
372369

373370
$(P A $(GLINK BreakStatement) will exit the loop.)
374371

0 commit comments

Comments
 (0)