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`
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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*
|
| 23 |
-
|
| 24 |
-
|
| 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
|
| 32 |
-
this
|
| 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
|
| 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
|
| 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 |
-
|
| 59 |
-
|
|
|
|
|
|
|
| 60 |
- otherwise, the target type is the type that `E2` would have after
|
| 61 |
-
applying the lvalue-to-rvalue
|
| 62 |
-
[[conv.array]]
|
| 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
|
| 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]],
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
|
| 93 |
-
Lvalue-to-rvalue
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 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
|
| 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
|
| 106 |
-
[[conv.fctptr]]
|
| 107 |
-
performed to bring them to their composite pointer type
|
| 108 |
-
|
| 109 |
-
- One or both of the second and third operands have pointer
|
| 110 |
-
type; pointer to member conversions
|
| 111 |
-
conversions
|
| 112 |
-
|
| 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 |
|