-
Notifications
You must be signed in to change notification settings - Fork 749
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
Comments
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. |
"typeid" issue submitted to CWG: http://lists.isocpp.org/core/2019/09/7236.php |
"most derived object" definition issue submitted to CWG: http://lists.isocpp.org/core/2019/09/7237.php |
@jensmaurer Any way to get access to the list? Publicly available one is quite outdated. |
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;
} |
That particular example is covered by the resolution of CWG1517. |
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 ofB
), 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 typeD
, whereB
is a base class ofD
, 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:
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)
The text was updated successfully, but these errors were encountered: