Closed xmh0511 closed 6 months ago
[expr.add] does not introduce the term "the end of an object". So, this remains extra room for interpreting the term.
Can't agree.
An interpretation is: Is any pointer that was pointed to an object(subobject) a pointer past the end of the object after adding 1?
Depends on the object.
At
#1
,ptr
points to the end of the subobjectarr[0]
and also is the start of the subobjectarr[1]
.
Per [expr.add], ptr
just points to arr[1]
and that's all.
Clearly define the term "a pointer past the end of an object"
The point is?
The relevant issue is https://github.com/cplusplus/draft/issues/4784
Does not look like an issue, at least the title.
Per [expr.add], ptr just points to arr[1] and that's all.
So, a pointer points to arr[n]
where arr
is an array with n elements can also be said the pointer just points to arr[n]
and that's all.
A pointer to a hypothetical element is equivalent to a pointer past the end the last element, so it is https://timsong-cpp.github.io/cppwp/n4868/basic.compound#def:pointer_past_the_end_of in the pointer value taxonomy
A pointer to a hypothetical element is equivalent to a pointer past the end the last element, so it is https://timsong-cpp.github.io/cppwp/n4868/basic.compound#def:pointer_past_the_end_of in the pointer value taxonomy
However, it does not mean we can conclude that a pointer to a hypothetical array element n of x is a pointer past then end of an object.
«a pointer past the end of the last element of an array x of n elements is considered to be equivalent to a pointer to a hypothetical array element n of x»
«a pointer past the end of the last element of an array x of n elements is considered to be equivalent to a pointer to a hypothetical array element n of x»
A
is considered to B
does not mean B
is A
. We said P+J
points to the hypothetical element when P+J = n
, in this sentence we didn't say a pointer points to the hypothetical element is a pointer past the end of arr[n-1]
, that is when you explicit say the pointer is what category then the pointer belongs to that category.
Equivalence is a symmetric relation
Equivalence is a symmetric relation
I think the strict equivalence relationship should be phrased as:
A pointer past the end of the last element of an array x of n elements is a pointer to a hypothetical array element n of x
Or:
A pointer to a hypothetical array element n of x is a pointer past the end of the last element of the array x of n elements
Then, the pointer points to the hypothetical array element is categorized as "a pointer past the end of an object"
Since [expr.add] didn't define what "a pointer past the end of an object" means, instead, [expr.add] says "hypothetical element", so, a plausible suggestion is to change the second bullet of the pointer category
Every value of pointer type is one of the following:
- [...]
- a pointer to a hypothetical element of an array.
Then, we can define what "a pointer past the end of an object" means
A pointer to a hypothetical array element n of an array x of n elements is considered to be a pointer past the end of the last element of x
[basic.compound] p3 already equates "past the end" with "hypothetical element" for purposes of pointer arithmetic, so I see no need to amend [expr.add]. No other hypothetical elements appear anywhere else in the text. And note that "pointer past the end" is simply a category name (like "blue" or"green") and, by itself, bears no particular meaning other than the properties ascribed to that name elsewhere in the text.
I understand there's a viewpoint that the definitions are backwards, but I'm not seeing any plausible misreading here; the suggestions offered don't feel like overall improvements.
And note that "pointer past the end" is simply a category name (like "blue" or"green")
So, we should use this name consistently throughout the whole document, however, [expr.eq] p3.1 uses
past the last element of a different complete object
[expr.const] p14.3 uses
past the end of such an object
It seems to we should be coherent to use the wording "past the end of xxx".
Full name of submitter (unless configured in github; will be published with the issue): Jim X
[basic.compound] p3:
[expr.add] does not introduce the term "the end of an object". So, this remains extra room for interpreting the term. An interpretation is: Is any pointer that was pointed to an object(subobject) a pointer past the end of the object after adding
1
? Specifically:At
#1
,ptr
points to the end of the subobjectarr[0]
and also is the start of the subobjectarr[1]
. Because a subobject is an object, since we didn't clear define the term "end of an object", so we can interpret it based on its literal meaning.Suggested Resolution
Clearly define the term "a pointer past the end of an object", which may be:
The relevant issue is https://github.com/cplusplus/draft/issues/4784