From Jason Turner

[expr.cond]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpiaqkw545/{from.md → to.md} +41 -41
tmp/tmpiaqkw545/{from.md → to.md} RENAMED
@@ -1,43 +1,41 @@
1
- ## Conditional operator <a id="expr.cond">[[expr.cond]]</a>
2
 
3
  ``` bnf
4
  conditional-expression:
5
  logical-or-expression
6
  logical-or-expression '?' expression ':' assignment-expression
7
  ```
8
 
9
  Conditional expressions group right-to-left. The first expression is
10
- contextually converted to `bool` (Clause  [[conv]]). It is evaluated and
11
- if it is `true`, the result of the conditional expression is the value
12
- of the second expression, otherwise that of the third expression. Only
13
- one of the second and third expressions is evaluated. Every value
14
- computation and side effect associated with the first expression is
15
- sequenced before every value computation and side effect associated with
16
- the second or third expression.
17
 
18
  If either the second or the third operand has type `void`, one of the
19
  following shall hold:
20
 
21
  - The second or the third operand (but not both) is a (possibly
22
- parenthesized) *throw-expression* ([[expr.throw]]); the result is of
23
- the type and value category of the other. The *conditional-expression*
24
- is a bit-field if that operand is a bit-field.
25
  - Both the second and the third operands have type `void`; the result is
26
  of type `void` and is a prvalue. \[*Note 1*: This includes the case
27
  where both operands are *throw-expression*s. — *end note*]
28
 
29
  Otherwise, if the second and third operand are glvalue bit-fields of the
30
  same value category and of types *cv1* `T` and *cv2* `T`, respectively,
31
- the operands are considered to be of type *cv* `T` for the remainder of
32
- this section, where *cv* is the union of *cv1* and *cv2*.
33
 
34
  Otherwise, if the second and third operand have different types and
35
  either has (possibly cv-qualified) class type, or if both are glvalues
36
  of the same value category and the same type except for
37
  cv-qualification, an attempt is made to form an implicit conversion
38
- sequence ([[over.best.ics]]) from each of those operands to the type of
39
  the other.
40
 
41
  [*Note 2*: Properties such as access, whether an operand is a
42
  bit-field, or whether a conversion function is deleted are ignored for
43
  that determination. — *end note*]
@@ -46,22 +44,24 @@ Attempts are made to form an implicit conversion sequence from an
46
  operand expression `E1` of type `T1` to a target type related to the
47
  type `T2` of the operand expression `E2` as follows:
48
 
49
  - If `E2` is an lvalue, the target type is “lvalue reference to `T2`”,
50
  subject to the constraint that in the conversion the reference must
51
- bind directly ([[dcl.init.ref]]) to an lvalue.
52
  - If `E2` is an xvalue, the target type is “rvalue reference to `T2`”,
53
  subject to the constraint that the reference must bind directly.
54
  - If `E2` is a prvalue or if neither of the conversion sequences above
55
  can be formed and at least one of the operands has (possibly
56
  cv-qualified) class type:
57
- - if `T1` and `T2` are the same class type (ignoring
58
- cv-qualification), or one is a base class of the other, and `T2` is
59
- at least as cv-qualified as `T1`, the target type is `T2`,
 
 
60
  - otherwise, the target type is the type that `E2` would have after
61
- applying the lvalue-to-rvalue ([[conv.lval]]), array-to-pointer (
62
- [[conv.array]]), and function-to-pointer ([[conv.func]]) standard
63
  conversions.
64
 
65
  Using this process, it is determined whether an implicit conversion
66
  sequence can be formed from the second operand to the target type
67
  determined for the third operand, and vice versa. If both sequences can
@@ -69,11 +69,11 @@ be formed, or one can be formed but it is the ambiguous conversion
69
  sequence, the program is ill-formed. If no conversion sequence can be
70
  formed, the operands are left unchanged and further checking is
71
  performed as described below. Otherwise, if exactly one conversion
72
  sequence can be formed, that conversion is applied to the chosen operand
73
  and the converted operand is used in place of the original operand for
74
- the remainder of this section.
75
 
76
  [*Note 3*: The conversion might be ill-formed even if an implicit
77
  conversion sequence could be formed. — *end note*]
78
 
79
  If the second and third operands are glvalues of the same value category
@@ -82,36 +82,36 @@ and it is a bit-field if the second or the third operand is a bit-field,
82
  or if both are bit-fields.
83
 
84
  Otherwise, the result is a prvalue. If the second and third operands do
85
  not have the same type, and either has (possibly cv-qualified) class
86
  type, overload resolution is used to determine the conversions (if any)
87
- to be applied to the operands ([[over.match.oper]],  [[over.built]]).
88
- If the overload resolution fails, the program is ill-formed. Otherwise,
89
- the conversions thus determined are applied, and the converted operands
90
- are used in place of the original operands for the remainder of this
91
- section.
92
 
93
- Lvalue-to-rvalue ([[conv.lval]]), array-to-pointer ([[conv.array]]),
94
- and function-to-pointer ([[conv.func]]) standard conversions are
95
- performed on the second and third operands. After those conversions, one
96
- of the following shall hold:
97
 
98
  - The second and third operands have the same type; the result is of
99
  that type and the result object is initialized using the selected
100
  operand.
101
  - The second and third operands have arithmetic or enumeration type; the
102
- usual arithmetic conversions are performed to bring them to a common
103
- type, and the result is of that type.
104
  - One or both of the second and third operands have pointer type;
105
- pointer conversions ([[conv.ptr]]), function pointer conversions (
106
- [[conv.fctptr]]), and qualification conversions ([[conv.qual]]) are
107
- performed to bring them to their composite pointer type (Clause 
108
- [[expr]]). The result is of the composite pointer type.
109
- - One or both of the second and third operands have pointer to member
110
- type; pointer to member conversions ([[conv.mem]]) and qualification
111
- conversions ([[conv.qual]]) are performed to bring them to their
112
- composite pointer type (Clause  [[expr]]). The result is of the
113
- composite pointer type.
114
  - Both the second and third operands have type `std::nullptr_t` or one
115
  has that type and the other is a null pointer constant. The result is
116
  of type `std::nullptr_t`.
117
 
 
1
+ ### Conditional operator <a id="expr.cond">[[expr.cond]]</a>
2
 
3
  ``` bnf
4
  conditional-expression:
5
  logical-or-expression
6
  logical-or-expression '?' expression ':' assignment-expression
7
  ```
8
 
9
  Conditional expressions group right-to-left. The first expression is
10
+ contextually converted to `bool` [[conv]]. It is evaluated and if it is
11
+ `true`, the result of the conditional expression is the value of the
12
+ second expression, otherwise that of the third expression. Only one of
13
+ the second and third expressions is evaluated. The first expression is
14
+ sequenced before the second or third expression [[intro.execution]].
 
 
15
 
16
  If either the second or the third operand has type `void`, one of the
17
  following shall hold:
18
 
19
  - The second or the third operand (but not both) is a (possibly
20
+ parenthesized) *throw-expression* [[expr.throw]]; the result is of the
21
+ type and value category of the other. The *conditional-expression* is
22
+ a bit-field if that operand is a bit-field.
23
  - Both the second and the third operands have type `void`; the result is
24
  of type `void` and is a prvalue. \[*Note 1*: This includes the case
25
  where both operands are *throw-expression*s. — *end note*]
26
 
27
  Otherwise, if the second and third operand are glvalue bit-fields of the
28
  same value category and of types *cv1* `T` and *cv2* `T`, respectively,
29
+ the operands are considered to be of type cv `T` for the remainder of
30
+ this subclause, where cv is the union of *cv1* and *cv2*.
31
 
32
  Otherwise, if the second and third operand have different types and
33
  either has (possibly cv-qualified) class type, or if both are glvalues
34
  of the same value category and the same type except for
35
  cv-qualification, an attempt is made to form an implicit conversion
36
+ sequence [[over.best.ics]] from each of those operands to the type of
37
  the other.
38
 
39
  [*Note 2*: Properties such as access, whether an operand is a
40
  bit-field, or whether a conversion function is deleted are ignored for
41
  that determination. — *end note*]
 
44
  operand expression `E1` of type `T1` to a target type related to the
45
  type `T2` of the operand expression `E2` as follows:
46
 
47
  - If `E2` is an lvalue, the target type is “lvalue reference to `T2`”,
48
  subject to the constraint that in the conversion the reference must
49
+ bind directly [[dcl.init.ref]] to a glvalue.
50
  - If `E2` is an xvalue, the target type is “rvalue reference to `T2`”,
51
  subject to the constraint that the reference must bind directly.
52
  - If `E2` is a prvalue or if neither of the conversion sequences above
53
  can be formed and at least one of the operands has (possibly
54
  cv-qualified) class type:
55
+ - if `T1` and `T2` are the same class type (ignoring cv-qualification)
56
+ and `T2` is at least as cv-qualified as `T1`, the target type is
57
+ `T2`,
58
+ - otherwise, if `T2` is a base class of `T1`, the target type is *cv1*
59
+ `T2`, where *cv1* denotes the cv-qualifiers of `T1`,
60
  - otherwise, the target type is the type that `E2` would have after
61
+ applying the lvalue-to-rvalue [[conv.lval]], array-to-pointer
62
+ [[conv.array]], and function-to-pointer [[conv.func]] standard
63
  conversions.
64
 
65
  Using this process, it is determined whether an implicit conversion
66
  sequence can be formed from the second operand to the target type
67
  determined for the third operand, and vice versa. If both sequences can
 
69
  sequence, the program is ill-formed. If no conversion sequence can be
70
  formed, the operands are left unchanged and further checking is
71
  performed as described below. Otherwise, if exactly one conversion
72
  sequence can be formed, that conversion is applied to the chosen operand
73
  and the converted operand is used in place of the original operand for
74
+ the remainder of this subclause.
75
 
76
  [*Note 3*: The conversion might be ill-formed even if an implicit
77
  conversion sequence could be formed. — *end note*]
78
 
79
  If the second and third operands are glvalues of the same value category
 
82
  or if both are bit-fields.
83
 
84
  Otherwise, the result is a prvalue. If the second and third operands do
85
  not have the same type, and either has (possibly cv-qualified) class
86
  type, overload resolution is used to determine the conversions (if any)
87
+ to be applied to the operands ([[over.match.oper]], [[over.built]]). If
88
+ the overload resolution fails, the program is ill-formed. Otherwise, the
89
+ conversions thus determined are applied, and the converted operands are
90
+ used in place of the original operands for the remainder of this
91
+ subclause.
92
 
93
+ Lvalue-to-rvalue [[conv.lval]], array-to-pointer [[conv.array]], and
94
+ function-to-pointer [[conv.func]] standard conversions are performed on
95
+ the second and third operands. After those conversions, one of the
96
+ following shall hold:
97
 
98
  - The second and third operands have the same type; the result is of
99
  that type and the result object is initialized using the selected
100
  operand.
101
  - The second and third operands have arithmetic or enumeration type; the
102
+ usual arithmetic conversions [[expr.arith.conv]] are performed to
103
+ bring them to a common type, and the result is of that type.
104
  - One or both of the second and third operands have pointer type;
105
+ pointer conversions [[conv.ptr]], function pointer conversions
106
+ [[conv.fctptr]], and qualification conversions [[conv.qual]] are
107
+ performed to bring them to their composite pointer type [[expr.type]].
108
+ The result is of the composite pointer type.
109
+ - One or both of the second and third operands have pointer-to-member
110
+ type; pointer to member conversions [[conv.mem]], function pointer
111
+ conversions [[conv.fctptr]], and qualification conversions
112
+ [[conv.qual]] are performed to bring them to their composite pointer
113
+ type [[expr.type]]. The result is of the composite pointer type.
114
  - Both the second and third operands have type `std::nullptr_t` or one
115
  has that type and the other is a null pointer constant. The result is
116
  of type `std::nullptr_t`.
117