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

[basic.compound] Clarify a pointer to a non-first element object of an array #6432

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

frederick-vs-ja
Copy link
Contributor

Such a pointer is categorized a pointer to an object, even if it may also point past the end of the previous array element. That is, [basic.compound]/3.1 applies first whenever possible.

I think we can just make clarification in the note.

Fixes #4784.
Fixes cplusplus/CWG#385.

@@ -5383,6 +5383,8 @@
after the end of the storage occupied by the object,
respectively.
\begin{note}
A pointer to an actual array element object is categorized as a pointer to an object,
even though it also points past the end of the previous array element, if any.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not get what does

it also points past the end of the previous array element

mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is as clear (or unclear) as "a pointer past the end of an object". Do you have better phrase for "the previous array element"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is as clear (or unclear) as "a pointer past the end of an object"

You mean a pointer to an array element is also a pointer past the end of the previous array element?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is as clear (or unclear) as "a pointer past the end of an object"

You mean a pointer to an array element is also a pointer past the end of the previous array element?

I think we can surely say a pointer that is "a pointer past the end of an object" points past the end of some given object. (Isn't this a tautology?) And then, given T a[2], there're two choices:

  1. there's a pointer value pointing past the end of a[0], and if so, a + 1 is exactly that value; or
  2. there's no pointer value pointing past the end of a[0].

Personally, I think choice 1 makes a little more sense. But if you think choice 2 makes more sense, we may abandon this PR and clarify with that choice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to [expr.add], a + 1 points to 1st array element. It can't be pointer past 0th at the same time, because Every value of pointer type is one of the following

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to [expr.add], a + 1 points to 1st array element. It can't be pointer past 0th at the same time, because Every value of pointer type is one of the following

Well, I think we agree on that a + 1 is categorized as a pointer to an object, and I don't think a + 1 is the "pointer past 0th" (Isn't this the content of this PR?).

What I wanted to clarify is that a + 1 points past the end of a[0] without being the pointer past the end of a[0].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a + 1 points past the end of a[0]

And this is my question: what does this mean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is my question: what does this mean

IMO when p points to an object o, we can generally say p + 1 points past the end of o (perhaps some base class subobjects should be excluded).

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