tmp/tmp22o1_ben/{from.md → to.md}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
## Additive operators <a id="expr.add">[[expr.add]]</a>
|
| 2 |
|
| 3 |
The additive operators `+` and `-` group left-to-right. The usual
|
| 4 |
-
arithmetic conversions are performed for operands of
|
| 5 |
-
enumeration type.
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
additive-expression:
|
| 9 |
multiplicative-expression
|
| 10 |
additive-expression '+' multiplicative-expression
|
|
@@ -26,39 +26,39 @@ For subtraction, one of the following shall hold:
|
|
| 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 that has integral type is added to or subtracted
|
| 32 |
-
|
| 33 |
-
expression `P` points to element x[i] of an array object `x` with n
|
| 34 |
-
elements, [^25] the expressions `P + J` and `J + P` (where `J` has the
|
| 35 |
-
value j) point to the (possibly-hypothetical) element x[i + j] if
|
| 36 |
-
0 ≤ i + j ≤ n; otherwise, the behavior is undefined. Likewise, the
|
| 37 |
-
expression `P - J` points to the (possibly-hypothetical) element
|
| 38 |
-
x[i - j] if 0 ≤ i - j ≤ n; otherwise, the behavior is undefined.
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 53 |
“pointer to cv `T`”, where `T` and the array element type are not
|
| 54 |
-
similar
|
| 55 |
|
| 56 |
[*Note 2*: In particular, a pointer to a base class cannot be used for
|
| 57 |
pointer arithmetic when the array contains objects of a derived class
|
| 58 |
type. — *end note*]
|
| 59 |
|
| 60 |
-
If the value 0 is added to or subtracted from a null pointer value, the
|
| 61 |
-
result is a null pointer value. If two null pointer values are
|
| 62 |
-
subtracted, the result compares equal to the value 0 converted to the
|
| 63 |
-
type `std::ptrdiff_t`.
|
| 64 |
-
|
|
|
|
| 1 |
+
### Additive operators <a id="expr.add">[[expr.add]]</a>
|
| 2 |
|
| 3 |
The additive operators `+` and `-` group left-to-right. The usual
|
| 4 |
+
arithmetic conversions [[expr.arith.conv]] are performed for operands of
|
| 5 |
+
arithmetic or enumeration type.
|
| 6 |
|
| 7 |
``` bnf
|
| 8 |
additive-expression:
|
| 9 |
multiplicative-expression
|
| 10 |
additive-expression '+' multiplicative-expression
|
|
|
|
| 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 an array element i of an array object `x`
|
| 37 |
+
with n elements [[dcl.array]], [^29] the expressions `P + J` and
|
| 38 |
+
`J + P` (where `J` has the value j) point to the
|
| 39 |
+
(possibly-hypothetical) array element i + j of `x` if 0 ≤ i + j ≤ n
|
| 40 |
+
and the expression `P - J` points to the (possibly-hypothetical) array
|
| 41 |
+
element i - j of `x` if 0 ≤ i - j ≤ n.
|
| 42 |
+
- Otherwise, the behavior is undefined.
|
| 43 |
|
| 44 |
+
When two pointer expressions `P` and `Q` are subtracted, the type of the
|
| 45 |
+
result is an *implementation-defined* signed integral type; this type
|
| 46 |
+
shall be the same type that is defined as `std::ptrdiff_t` in the
|
| 47 |
+
`<cstddef>` header [[support.types.layout]].
|
| 48 |
+
|
| 49 |
+
- If `P` and `Q` both evaluate to null pointer values, the result is 0.
|
| 50 |
+
- Otherwise, if `P` and `Q` point to, respectively, array elements i and
|
| 51 |
+
j of the same array object `x`, the expression `P - Q` has the value
|
| 52 |
+
i - j.
|
| 53 |
+
- Otherwise, the behavior is undefined. \[*Note 1*: If the value i - j
|
| 54 |
+
is not in the range of representable values of type `std::ptrdiff_t`,
|
| 55 |
+
the behavior is undefined. — *end note*]
|
| 56 |
|
| 57 |
For addition or subtraction, if the expressions `P` or `Q` have type
|
| 58 |
“pointer to cv `T`”, where `T` and the array element type are not
|
| 59 |
+
similar [[conv.qual]], the behavior is undefined.
|
| 60 |
|
| 61 |
[*Note 2*: In particular, a pointer to a base class cannot be used for
|
| 62 |
pointer arithmetic when the array contains objects of a derived class
|
| 63 |
type. — *end note*]
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|