Reputation: 5270
[N4687]
3.9 [defns.dynamic.type]
dynamic type
〈glvalue〉 type of the most derived object (4.5) to which the glvalue refers [Example: If a pointer (11.3.1) p whose static type is “pointer to class B” is pointing to an object of class D, derived from B (Clause 13), the dynamic type of the expression *p is “D”. References (11.3.2) are treated similarly. — end example ]
3.10 [defns.dynamic.type.prvalue]
dynamic type
〈prvalue〉 static type of the prvalue expression
Most questions about dynamic type concrete on 3.9. but I still can't understand the meaning of 3.10.
Here is cppreference's description:
A prvalue cannot be polymorphic: the dynamic type of the object it identifies is always the type of the expression.
3.9 tells me dynamic type means the determination of type has to be delayed at runtime.
I have several questions about 3.10:
What the relationship between 3.9 and 3.10
Why prvalue is emphasized?
Does it mean prvalue's dynamic and static type is always the same?
Upvotes: 2
Views: 190
Reputation: 119382
What the relationship between 3.9 and 3.10
They both define "dynamic type". Informally, the dynamic type of an expression is the type of the complete object that contains the object denoted by the expression.
Why prvalue is emphasized?
Perhaps for the sake of clarity, they decided to explain separately what "dynamic type" means for glvalues and prvalues. The philosophy (before C++17) is that a glvalue is something that refers to an object or function while a prvalue is the value of an object, so they are somewhat different simply by nature.
Does it mean prvalue's dynamic and static type is always the same?
Yes. While it's possible to create a glvalue that refers to a base class subobject of another object, a prvalue doesn't refer to anything, and, as such, is what it is. Any attempt to create a prvalue that's a subobject of another object will just create a copy of the subobject instead, and that copy is a complete object.
Upvotes: 6
Reputation: 141628
3.9 is defining "dynamic type of a glvalue", and 3.10 is defining "dynamic type of a prvalue".
The document is using slightly unusual formatting. These two sections should be taken as separate definitions with no overlap. (All expressions are either glvalues or prvalues, but not both at once).
Upvotes: 1