Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A pointer past the end of the last element should have an explicit pointer value category and consistently use that term #4784

Open
xmh0511 opened this issue Jul 28, 2021 · 2 comments · May be fixed by #6432

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 28, 2021

[basic.compound#3]

For purposes of pointer arithmetic ([expr.add]) and comparison ([expr.rel], [expr.eq]), 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 and an object of type T that is not an array element is considered to belong to an array with one element of type T.

It is a bit obscure to distinct the difference between the wording "a pointer past the end of the last element " and "a pointer past the end of the first(or the other element but not the last) element", which one can be considered to have the pointer value category "a pointer past the end of an object"? Presumably, we should explicitly categorize the former case to have "a pointer past the end of an object".

a pointer to a hypothetical array element n of x is said as a pointer past the end of the object that is the element n-1 of x.

This proposal would make it be clear that only a pointer past the end of the last element of an array has that pointer value. And which object the pointer value is talking about.

Terms should be consistent:

[expr.eq#3.1]

If one pointer represents the address of a complete object, and another pointer represents the address one past the last element of a different complete object, the result of the comparison is unspecified.

Shouldn't we say that?

another pointer represents the address one past the end of a different complete object

Since the complete object belongs to an array with a single element for comparison purposes, "last element of a different complete object" sounds a bit strange.

The difference between "past the last element of an array" and "past the end of the last element of an array"
In these footnotes [expr.add#footnote-72], [expr.rel#footnote-73], we use the former, however, the normative rule in [basic.compound#3] is strictly using the latter. I think we should uniformly use the same utterance.

@xmh0511 xmh0511 changed the title A pointer past the end of the last element should have an explicit pointer category and consistently use that term A pointer past the end of the last element should have an explicit pointer value category and consistently use that term Jul 28, 2021
@languagelawyer
Copy link
Contributor

A pointer past the end of the last element should have an explicit pointer value category

Here it is: https://timsong-cpp.github.io/cppwp/n4868/basic.compound#def:pointer_past_the_end_of

@frederick-vs-ja
Copy link
Contributor

I think we can just make clarification in the following note in [basic.compound].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants