tmp/tmpku9myugc/{from.md → to.md}
RENAMED
|
@@ -1,64 +1,67 @@
|
|
| 1 |
### Additive operators <a id="expr.add">[[expr.add]]</a>
|
| 2 |
|
| 3 |
-
The additive operators `+` and `-` group left-to-right.
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
additive-expression:
|
| 9 |
multiplicative-expression
|
| 10 |
additive-expression '+' multiplicative-expression
|
| 11 |
additive-expression '-' multiplicative-expression
|
| 12 |
```
|
| 13 |
|
| 14 |
-
For addition, either both operands shall have arithmetic or
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
unscoped enumeration type.
|
| 18 |
|
| 19 |
For subtraction, one of the following shall hold:
|
| 20 |
|
| 21 |
-
- both operands have arithmetic
|
| 22 |
- both operands are pointers to cv-qualified or cv-unqualified versions
|
| 23 |
of the same completely-defined object type; or
|
| 24 |
- the left operand is a pointer to a completely-defined object type and
|
| 25 |
-
the right operand has integral
|
| 26 |
|
| 27 |
The result of the binary `+` operator is the sum of the operands. The
|
| 28 |
result of the binary `-` operator is the difference resulting from the
|
| 29 |
subtraction of the second operand from the first.
|
| 30 |
|
| 31 |
When an expression `J` that has integral type is added to or subtracted
|
| 32 |
from an expression `P` of pointer type, the result has the type of `P`.
|
| 33 |
|
| 34 |
- If `P` evaluates to a null pointer value and `J` evaluates to 0, the
|
| 35 |
result is a null pointer value.
|
| 36 |
-
- Otherwise, if `P` points to
|
| 37 |
-
with n elements [[dcl.array]],[^
|
| 38 |
-
`J + P` (where `J` has the value j) point to
|
| 39 |
-
(possibly-hypothetical) array element i + j of `x` if
|
| 40 |
-
and the expression `P - J` points to the
|
| 41 |
-
element i - j of `x` if 0 ≤ i - j ≤ n.
|
| 42 |
- Otherwise, the behavior is undefined.
|
| 43 |
|
| 44 |
[*Note 1*: Adding a value other than 0 or 1 to a pointer to a base
|
| 45 |
class subobject, a member subobject, or a complete object results in
|
| 46 |
undefined behavior. — *end note*]
|
| 47 |
|
| 48 |
When two pointer expressions `P` and `Q` are subtracted, the type of the
|
| 49 |
result is an *implementation-defined* signed integral type; this type
|
| 50 |
-
shall be the same type that is
|
| 51 |
`<cstddef>` header [[support.types.layout]].
|
| 52 |
|
| 53 |
- If `P` and `Q` both evaluate to null pointer values, the result is 0.
|
| 54 |
- Otherwise, if `P` and `Q` point to, respectively, array elements i and
|
| 55 |
j of the same array object `x`, the expression `P - Q` has the value
|
| 56 |
-
i - j.
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
|
| 61 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 62 |
“pointer to cv `T`”, where `T` and the array element type are not
|
| 63 |
similar [[conv.qual]], the behavior is undefined.
|
| 64 |
|
|
|
|
| 1 |
### Additive operators <a id="expr.add">[[expr.add]]</a>
|
| 2 |
|
| 3 |
+
The additive operators `+` and `-` group left-to-right. Each operand
|
| 4 |
+
shall be a prvalue. If both operands have arithmetic or unscoped
|
| 5 |
+
enumeration type, the usual arithmetic conversions [[expr.arith.conv]]
|
| 6 |
+
are performed. Otherwise, if one operand has arithmetic or unscoped
|
| 7 |
+
enumeration type, integral promotion is applied [[conv.prom]] to that
|
| 8 |
+
operand. A converted or promoted operand is used in place of the
|
| 9 |
+
corresponding original operand for the remainder of this section.
|
| 10 |
|
| 11 |
``` bnf
|
| 12 |
additive-expression:
|
| 13 |
multiplicative-expression
|
| 14 |
additive-expression '+' multiplicative-expression
|
| 15 |
additive-expression '-' multiplicative-expression
|
| 16 |
```
|
| 17 |
|
| 18 |
+
For addition, either both operands shall have arithmetic type, or one
|
| 19 |
+
operand shall be a pointer to a completely-defined object type and the
|
| 20 |
+
other shall have integral type.
|
|
|
|
| 21 |
|
| 22 |
For subtraction, one of the following shall hold:
|
| 23 |
|
| 24 |
+
- both operands have arithmetic type; or
|
| 25 |
- both operands are pointers to cv-qualified or cv-unqualified versions
|
| 26 |
of the same completely-defined object type; or
|
| 27 |
- the left operand is a pointer to a completely-defined object type and
|
| 28 |
+
the right operand has integral type.
|
| 29 |
|
| 30 |
The result of the binary `+` operator is the sum of the operands. The
|
| 31 |
result of the binary `-` operator is the difference resulting from the
|
| 32 |
subtraction of the second operand from the first.
|
| 33 |
|
| 34 |
When an expression `J` that has integral type is added to or subtracted
|
| 35 |
from an expression `P` of pointer type, the result has the type of `P`.
|
| 36 |
|
| 37 |
- If `P` evaluates to a null pointer value and `J` evaluates to 0, the
|
| 38 |
result is a null pointer value.
|
| 39 |
+
- Otherwise, if `P` points to a (possibly-hypothetical) array element i
|
| 40 |
+
of an array object `x` with n elements [[dcl.array]],[^26] the
|
| 41 |
+
expressions `P + J` and `J + P` (where `J` has the value j) point to
|
| 42 |
+
the (possibly-hypothetical) array element i + j of `x` if
|
| 43 |
+
0 ≤ i + j ≤ n and the expression `P - J` points to the
|
| 44 |
+
(possibly-hypothetical) array element i - j of `x` if 0 ≤ i - j ≤ n.
|
| 45 |
- Otherwise, the behavior is undefined.
|
| 46 |
|
| 47 |
[*Note 1*: Adding a value other than 0 or 1 to a pointer to a base
|
| 48 |
class subobject, a member subobject, or a complete object results in
|
| 49 |
undefined behavior. — *end note*]
|
| 50 |
|
| 51 |
When two pointer expressions `P` and `Q` are subtracted, the type of the
|
| 52 |
result is an *implementation-defined* signed integral type; this type
|
| 53 |
+
shall be the same type that is named by `std::ptrdiff_t` in the
|
| 54 |
`<cstddef>` header [[support.types.layout]].
|
| 55 |
|
| 56 |
- If `P` and `Q` both evaluate to null pointer values, the result is 0.
|
| 57 |
- Otherwise, if `P` and `Q` point to, respectively, array elements i and
|
| 58 |
j of the same array object `x`, the expression `P - Q` has the value
|
| 59 |
+
i - j. \[*Note 2*: If the value i - j is not in the range of
|
| 60 |
+
representable values of type `std::ptrdiff_t`, the behavior is
|
| 61 |
+
undefined [[expr.pre]]. — *end note*]
|
| 62 |
+
- Otherwise, the behavior is undefined.
|
| 63 |
|
| 64 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 65 |
“pointer to cv `T`”, where `T` and the array element type are not
|
| 66 |
similar [[conv.qual]], the behavior is undefined.
|
| 67 |
|