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.lval,expr.delete] 'dynamic type' refers to lvalues, not objects #2265

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

Conversation

jensmaurer
Copy link
Member

Fixes #2190.

@jensmaurer
Copy link
Member Author

I don't really like the edits to [expr.delete]. The issue here is that the operand of the delete-expression is a pointer, but "dynamic type" is only defined for lvalues. We can either add a definition of "dynamic type" for pointers (deferring to the glvalue case), or we can locally construct an lvalue in [expr.delete]. I've done the latter, but I'm not totally happy with it. Comments welcome; in particular the [basic.lval] rewrites are rather extensive.

@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Jul 17, 2018
@jensmaurer
Copy link
Member Author

... and while we're at it, the definition of "dynamic type" seems to belong to [expr.prop], since it's a property of an expression.

\grammarterm{delete-expression}\iref{class.free}.
This assures that a deallocation function
is available for a \grammarterm{delete-expression}\iref{class.free},
even if the static type of the object to which the operand points
Copy link
Contributor

Choose a reason for hiding this comment

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

"static type" is also a property of an expression :(
http://eel.is/c++draft/intro.defs#defns.static.type

expression, if the dynamic type of the object to be deleted differs from its
static type, the behavior is undefined.
the static type shall be
a base class of the dynamic type of the object to be deleted
Copy link
Contributor

Choose a reason for hiding this comment

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

"dynamic type" still refers to the object here.

@jensmaurer
Copy link
Member Author

Editorial meeting: Maybe replace "dynamic type" simply with "most derived type of the object the glvalue / pointer refers to". Well, no, "dynamic type" is too ingrained in the history of C++. "... even if the pointer points to a base class subobject."

"assures" -> "ensures"

undefined:\footnote{The intent of this list is to specify those circumstances in which an
object may or may not be aliased.}
If a program attempts to access the stored value of an object of type \tcode{T}
through a glvalue whose dynamic type is not one of the following types,
Copy link
Member Author

Choose a reason for hiding this comment

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

use "static type" here


\item a type that is the signed or unsigned type corresponding to a
cv-qualified version of the dynamic type of the object,
\item a type that is the signed or unsigned type corresponding to \cv{} \tcode{T},

\item an aggregate or union type that includes one of the aforementioned types among its
elements or non-static data members (including, recursively, an element or non-static data member of a
subaggregate or contained union),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is useless in C++, except for the copy of a union. Oh, covered by the final bullet, which covers object representations = arrays of unsigned char.

@@ -2875,10 +2865,10 @@
of the object expression is called; such a call is referred to as a
\defnx{virtual function call}{function!virtual function call}.
\begin{note}
The dynamic type is the type of the object referred to by the
current value of the object expression. \ref{class.cdtor}~describes the
behavior of virtual function calls when the object expression
Copy link
Member Author

Choose a reason for hiding this comment

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

Simply strike the first sentence of the note instead of trying to fix it.

@zygoloid zygoloid added changes requested Changes to the wording or approach have been requested and not yet applied. after-motions Pull request is to be applied after the pending edits from WG21 straw polls have been applied. and removed decision-required A decision of the editorial group (or the Project Editor) is required. after-motions Pull request is to be applied after the pending edits from WG21 straw polls have been applied. labels Feb 22, 2019
@jensmaurer
Copy link
Member Author

Editorial issue: Changes to [basic.lval] collide with CWG 2051.

@tkoeppe
Copy link
Contributor

tkoeppe commented Mar 15, 2019

@jensmaurer: Rebase?

@jensmaurer
Copy link
Member Author

@tkoeppe, this needs (a lot) more work than a simple rebase. Not right now.

@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Jun 15, 2021
@tkoeppe
Copy link
Contributor

tkoeppe commented Jun 22, 2021

@jensmaurer: Is there still something left to pursue here?

@jensmaurer
Copy link
Member Author

Yes, I think this needs a bit of love + care at some later point. There is a terminological haziness around "static type" and "dynamic type" that ought to be fixed, possibly by eradicating "static type" entirely (it's simply the type of the expression) and doing some goodness to "dynamic type". After all, "dynamic type" means "type of the (most derived) object" (unrelated to any specific expression), but "static type" means "type of the expression as written in the source and specified by [expr]".

Crazy talk such as "the static type of the object to be deleted" just needs to go; talking about the static type of an object is a category error as explained above.

@jensmaurer jensmaurer removed the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Nov 22, 2021
@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Apr 16, 2024
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.

"dynamic type" is defined as a property of expressions but sometimes used as a property of objects
5 participants