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

[conv.ptr] Fix unclear specification of derived-to-base conversions for null pointers #3823

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sdkrystian
Copy link
Contributor

@sdkrystian sdkrystian commented Mar 5, 2020

[conv.ptr] p3 states:

The result of the conversion is a pointer to the base class subobject of the derived class object. The null pointer value is converted to the null pointer value of the destination type.

While null pointer values are established as a singular value a pointer can have in [basic.compound], it is unique to the pointer type. Saying "The null pointer value" is rather unclear in what it refers to, as there is no single null pointer value.

object. The null pointer value is converted to the null pointer value of
the destination type.
that necessitates this conversion is ill-formed.
If the source value is a null pointer value, the result is a
Copy link
Member

Choose a reason for hiding this comment

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

What's the "source value"? Can we reformulate without using this novel term?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jensmaurer In [conv], there's a mixture of "source value", "source expression" and "source prvalue". I suppose that the best replacement here would be "source prvalue".

Copy link
Member

Choose a reason for hiding this comment

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

Sounds better, because it aligns with the phrasing in the "If" at the start of the paragraph.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jensmaurer Applied

Copy link
Member

Choose a reason for hiding this comment

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

I really don't like using "source prvalue" here. A prvalue is a kind of expression, so this sounds like it's talking about a (static) property of the expression, which it's not.

I think something like "A null pointer value of the source type is converted to a null pointer value of the destination type. A pointer to an object o of type D is converted to a pointer to the B base class subobject of o." would work, and fits much better into our pointer value taxonomy in [basic.compound]. Arguably this would need CWG review since it makes it much more clear that such a conversion applied to any other pointer value is undefined.

@sdkrystian
Copy link
Contributor Author

sdkrystian commented Mar 6, 2020

@jensmaurer I applied the changes in [conv.ptr] to [conv.mem], [expr.static.cast], [expr.reinterpret.cast], and [expr.const.cast]. Another small error I fixed was that in [conv.mem] we say "The result refers to the member in D's instance of B"; "instance" here was replaced with "base class subobject".

@zygoloid zygoloid added the changes requested Changes to the wording or approach have been requested and not yet applied. label Mar 13, 2020
@jensmaurer jensmaurer added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Oct 29, 2020
@jensmaurer
Copy link
Member

@sdkrystian, could you please rebase and implement @zygoloid's suggestion, which sounds like an improvement?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes requested Changes to the wording or approach have been requested and not yet applied. needs rebase The pull request needs a git rebase to resolve merge conflicts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants