Date: Mon, 6 Sep 2021 12:23:43 +0100
On Mon, 6 Sep 2021, 11:50 Vladimir Grigoriev via Std-Discussion, <
std-discussion_at_[hidden]> wrote:
> 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 )
> {
> a->f();
> }
>
> 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?
>
>
No, because while a1 is a complete object it is not the complete object of
x.
Note that while a2 is the complete object of x, it is also x, so passing
&a2 to the constructor of a2 would also be well 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]
> <http:///compose?To=std%2ddiscussion_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
> (7.6.1.4) 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
> subobject.
>
> 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
> Std-Discussion_at_[hidden]
> <http:///compose?To=Std%2dDiscussion_at_[hidden]>
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
std-discussion_at_[hidden]> wrote:
> 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 )
> {
> a->f();
> }
>
> 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?
>
>
No, because while a1 is a complete object it is not the complete object of
x.
Note that while a2 is the complete object of x, it is also x, so passing
&a2 to the constructor of a2 would also be well 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]
> <http:///compose?To=std%2ddiscussion_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
> (7.6.1.4) 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
> subobject.
>
> 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
> Std-Discussion_at_[hidden]
> <http:///compose?To=Std%2dDiscussion_at_[hidden]>
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
>
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
Received on 2021-09-06 06:23:58