C++ Logo


Advanced search

Re: Construction and destruction

From: Vladimir Grigoriev <vlad.moscow_at_[hidden]>
Date: Mon, 06 Sep 2021 13:50:06 +0300
I am sorry but I do not see ay relation between the statement I provided from the C++ Standard and the following example and your explanation. The statement is entirely unclear.
For example consider the following program
#include <iostream>
struct A
    A() = default;
    A( const A *a )
    virtual void f() const
        std::cout << "Hello!\n";
int main() 
    A a1;
    A a2( &a1 );
    return 0;
Here the object a1 is a complete object. Does it mean that the program ill-formed?
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
>Суббота, 28 августа 2021, 16:51 +03:00 от Jason McKesson via Std-Discussion <std-discussion_at_[hidden]>:
>On Sat, Aug 28, 2021 at 6:11 AM Vladimir Grigoriev via Std-Discussion
>< std-discussion_at_[hidden] > wrote:
>> This phrase in the paragraph #4 of the section «Construction and destruction»
>> «If the virtual function call uses an explicit class member access ( and the object expression refers to the complete object of x or one of that object’s base class subobjects but not x or one of its base class subobjects, the behavior is undefined.»
>> What is the difference between the complete object of x or one of that object’s base class subobjects and the x or one of its base class subobjects?
>The term "complete object" is defined in [intro.object]. It is an
>object which is not a subobject of another object.
>`x` is the object being constructed, and it may be the subobject of
>another object. Thus, the "complete object of x" is the complete
>object in which `x` is a subobject, or just `x` if `x` is not a
>Basically, what the text is saying is that if you try to use explicit
>member access to call a virtual function that goes *outside* of the
>inheritance graph of `x`, you get UB.
>Std-Discussion mailing list

Received on 2021-09-06 05:50:26