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

[expr.reinterpret.cast] Fix a note #4080

Merged
merged 1 commit into from Jul 16, 2020

Conversation

languagelawyer
Copy link
Contributor

struct S { int i; } s;

auto fp = reinterpret_cast<float*>(&s); // the value of `fp` is  "pointer to s"

reinterpret_cast<float*>(reinterpret_cast<int*>(fp));
// converting to `int*` and back to `float*` does NOT yield the original pointer value,
// because the value became "pointer to s.i" when casting to `int*`.

@hubert-reinterpretcast

@hubert-reinterpretcast
Copy link
Contributor

Would it make sense to try to salvage the note by indicating that the resulting pointer could also be a pointer to an object that is pointer-interconvertible with the object (if any) to which the original pointer points?

@jensmaurer
Copy link
Member

It sounds reasonable to highlight the round-trip guarantee, but that needs a bit of wording surgery. Maybe just avoiding phrasing in terms of types would help. "If a pointer to a type T1 is converted to type "pointer to T2" and back to "pointer to T1" and (the stars are aligned correctly), you get the original pointer value."

@hubert-reinterpretcast
Copy link
Contributor

I think just making the original pointer value something more specific works:
Converting a prvalue of type "pointer to T1" that points to an object of type T1 [ ... ]

@languagelawyer languagelawyer changed the title [expr.reinterpret.cast] Remove an incorrect note [expr.reinterpret.cast] Fix a note Jul 16, 2020
@languagelawyer languagelawyer force-pushed the reinterpretcast branch 3 times, most recently from b4ff6ae to 29a242a Compare July 16, 2020 14:26
@languagelawyer
Copy link
Contributor Author

I didn't like "a prvalue that points" and rewrote as "a pointer that points", also, since T1 became known to be an object type, I had to change the "where" part. I also decided to remove parens and reflow the sentence.

@hubert-reinterpretcast
Copy link
Contributor

LGTM, but I have no commit access.

@jensmaurer
Copy link
Member

@hubert-reinterpretcast , thanks for the review.

@jensmaurer jensmaurer merged commit b1df284 into cplusplus:master Jul 16, 2020
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 this pull request may close these issues.

None yet

3 participants