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

[intro.object] Definition of "most derived object" does not match its use CWG 1517 #2950

Open
sdkrystian opened this issue Jun 30, 2019 · 6 comments
Labels
cwg Issue must be reviewed by CWG.

Comments

@sdkrystian
Copy link
Contributor

According to [intro.object] p6, a most derived object is an object of a most derived class type or of a non-class type, however, almost all mentions of it in the standard use it as a property that relates two object to each other (Ex: A is the most derived object of B), while the definition currently just describes an object (Ex: A is a most derived object).

Examples of use:
[defns.dynamic.type] type of the most derived object to which the glvalue refers

In this definition, most derived object is used as if it relates two objects, which it doesn't. What this means is that "dynamic type" is undefined for an expression that refers to an object that is not a complete object. For instance, if you had a a reference to B, and you initialized it with an object of type D, where B is a base class of D, the reference would be bound to the base class subobject, rather than the object itself, so the dynamic type of an expression naming that reference would be undefined, according to the current definition.

[class.ctor] p5 Here, the wording alludes to "the most derived object", referring to some specific object, that has not been defined.

There are many such cases like these, and can be fixed by defining "most derived object" as a term that relates two objects like so:

The most derived object of an object B is determined as follows:

- If B is a complete object, member subobject, or array element, or, if B is of non-class type, the msot derived object of B is B
- Otherwise, the most derived object of B is the most derived object of the object containing B

Some rewording would be required for clauses that currently refer to most derived objects (they are incorrect even now), which I will submit in a pull request if this change is deemed good (I'm on vacation right now, so it will take about a week)

@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Jul 4, 2019
@jensmaurer jensmaurer changed the title [intro.object] Definition of "most derived object" does not match it's use [intro.object] Definition of "most derived object" does not match its use Jul 4, 2019
@jensmaurer
Copy link
Member

jensmaurer commented Jul 16, 2019

Editorial meeting: During the period of construction, the dynamic type might be different from the most derived object. "typeid" currently refers to most derived object, though. See CWG1517 for rewrite of class.ctor. The "type of an object" should not change throughout the lifetime.

@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. and removed decision-required A decision of the editorial group (or the Project Editor) is required. labels Jul 16, 2019
@jensmaurer
Copy link
Member

"typeid" issue submitted to CWG: http://lists.isocpp.org/core/2019/09/7236.php

@jensmaurer
Copy link
Member

"most derived object" definition issue submitted to CWG: http://lists.isocpp.org/core/2019/09/7237.php

@sdkrystian
Copy link
Contributor Author

@jensmaurer Any way to get access to the list? Publicly available one is quite outdated.

@jensmaurer jensmaurer changed the title [intro.object] Definition of "most derived object" does not match its use [intro.object] Definition of "most derived object" does not match its use CWG 1517 Jun 14, 2020
@xmh0511
Copy link
Contributor

xmh0511 commented Aug 19, 2021

I'm wondering what is the most derived object in this example as per the current definition

struct A{
    virtual ~A(){}
};
struct B:A{
    B(){
        A* ptr = this;
        std::cout<< typeid(*ptr).name()<<std::endl;  // [expr.typeid] p2 applies here.
    }
};
struct C:B{

};
int main() {
    C c;
}

@jensmaurer
Copy link
Member

jensmaurer commented Aug 19, 2021

That particular example is covered by the resolution of CWG1517.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG.
Projects
None yet
Development

No branches or pull requests

3 participants