From Jason Turner

[stmt.if]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp64p1lv80/{from.md → to.md} +29 -15
tmp/tmp64p1lv80/{from.md → to.md} RENAMED
@@ -1,34 +1,34 @@
1
  ### The `if` statement <a id="stmt.if">[[stmt.if]]</a>
2
 
3
- If the condition ([[stmt.select]]) yields `true` the first substatement
4
- is executed. If the `else` part of the selection statement is present
5
- and the condition yields `false`, the second substatement is executed.
6
- If the first substatement is reached via a label, the condition is not
7
  evaluated and the second substatement is not executed. In the second
8
  form of `if` statement (the one including `else`), if the first
9
  substatement is also an `if` statement then that inner `if` statement
10
  shall contain an `else` part.[^1]
11
 
12
  If the `if` statement is of the form `if constexpr`, the value of the
13
  condition shall be a contextually converted constant expression of type
14
- `bool` ([[expr.const]]); this form is called a *constexpr if*
15
- statement. If the value of the converted condition is `false`, the first
16
  substatement is a *discarded statement*, otherwise the second
17
  substatement, if present, is a discarded statement. During the
18
- instantation of an enclosing templated entity (Clause  [[temp]]), if the
19
  condition is not value-dependent after its instantiation, the discarded
20
  substatement (if any) is not instantiated.
21
 
22
- [*Note 1*: Odr-uses ([[basic.def.odr]]) in a discarded statement do
23
- not require an entity to be defined. — *end note*]
24
 
25
  A `case` or `default` label appearing within such an `if` statement
26
- shall be associated with a `switch` statement ([[stmt.switch]]) within
27
- the same `if` statement. A label ([[stmt.label]]) declared in a
28
- substatement of a constexpr if statement shall only be referred to by a
29
- statement ([[stmt.goto]]) in the same substatement.
30
 
31
  [*Example 1*:
32
 
33
  ``` cpp
34
  template<typename T, typename ... Rest> void g(T&& p, Rest&& ...rs) {
@@ -53,21 +53,35 @@ int f() {
53
  — *end example*]
54
 
55
  An `if` statement of the form
56
 
57
  ``` bnf
58
- 'if constexprₒₚₜ (' init-statement condition ')' statement
59
  ```
60
 
61
  is equivalent to
62
 
 
 
 
 
 
 
 
63
  and an `if` statement of the form
64
 
65
  ``` bnf
66
- 'if constexprₒₚₜ (' init-statement condition ')' statement 'else' statement
67
  ```
68
 
69
  is equivalent to
70
 
 
 
 
 
 
 
 
71
  except that names declared in the *init-statement* are in the same
72
  declarative region as those declared in the *condition*.
73
 
 
1
  ### The `if` statement <a id="stmt.if">[[stmt.if]]</a>
2
 
3
+ If the condition [[stmt.select]] yields `true` the first substatement is
4
+ executed. If the `else` part of the selection statement is present and
5
+ the condition yields `false`, the second substatement is executed. If
6
+ the first substatement is reached via a label, the condition is not
7
  evaluated and the second substatement is not executed. In the second
8
  form of `if` statement (the one including `else`), if the first
9
  substatement is also an `if` statement then that inner `if` statement
10
  shall contain an `else` part.[^1]
11
 
12
  If the `if` statement is of the form `if constexpr`, the value of the
13
  condition shall be a contextually converted constant expression of type
14
+ `bool` [[expr.const]]; this form is called a *constexpr if* statement.
15
+ If the value of the converted condition is `false`, the first
16
  substatement is a *discarded statement*, otherwise the second
17
  substatement, if present, is a discarded statement. During the
18
+ instantiation of an enclosing templated entity [[temp.pre]], if the
19
  condition is not value-dependent after its instantiation, the discarded
20
  substatement (if any) is not instantiated.
21
 
22
+ [*Note 1*: Odr-uses [[basic.def.odr]] in a discarded statement do not
23
+ require an entity to be defined. — *end note*]
24
 
25
  A `case` or `default` label appearing within such an `if` statement
26
+ shall be associated with a `switch` statement [[stmt.switch]] within the
27
+ same `if` statement. A label [[stmt.label]] declared in a substatement
28
+ of a constexpr if statement shall only be referred to by a statement
29
+ [[stmt.goto]] in the same substatement.
30
 
31
  [*Example 1*:
32
 
33
  ``` cpp
34
  template<typename T, typename ... Rest> void g(T&& p, Rest&& ...rs) {
 
53
  — *end example*]
54
 
55
  An `if` statement of the form
56
 
57
  ``` bnf
58
+ if constexprₒₚₜ '(' init-statement condition ')' statement
59
  ```
60
 
61
  is equivalent to
62
 
63
+ ``` bnf
64
+ '{'
65
+ init-statement
66
+ if constexprₒₚₜ '(' condition ')' statement
67
+ '}'
68
+ ```
69
+
70
  and an `if` statement of the form
71
 
72
  ``` bnf
73
+ if constexprₒₚₜ '(' init-statement condition ')' statement else statement
74
  ```
75
 
76
  is equivalent to
77
 
78
+ ``` bnf
79
+ '{'
80
+ init-statement
81
+ if constexprₒₚₜ '(' condition ')' statement else statement
82
+ '}'
83
+ ```
84
+
85
  except that names declared in the *init-statement* are in the same
86
  declarative region as those declared in the *condition*.
87