Title
Initialization of class from self
Status
nad
Section
11.9.2 [class.expl.init]
Submitter
Sergey P. Derevyago

Created on 2002-07-11.00:00:00 last changed 268 months ago

Messages

Date: 2002-10-15.00:00:00

Notes from October 2002 meeting:

6.7.3 [basic.life] paragraph 6 indicates that the references here are valid. It's permitted to take the address of a class object before it is fully initialized, and it's permitted to pass it as an argument to a reference parameter as long as the reference can bind directly. Except for the failure to cast the pointers to void * for the %p in the printfs, these examples are standard-conforming.

Date: 2002-07-11.00:00:00

Is the following code well-formed?

 struct A { /* */ };

 int main()
 {
  A a=a;
 }

Note, that { int a=a; } is pretty legal.

And if so, what is the semantics of the self-initialization of UDT? For example

 #include <stdio.h>

 struct A {
        A()           { printf("A::A() %p\n",            this);     }
        A(const A& a) { printf("A::A(const A&) %p %p\n", this, &a); }
        ~A()          { printf("A::~A() %p\n",           this);     }
 };

 int main()
 {
  A a=a;
 }

can be compiled and prints:

A::A(const A&) 0253FDD8 0253FDD8
A::~A() 0253FDD8

(on some implementations).

History
Date User Action Args
2002-11-08 00:00:00adminsetmessages: + msg785
2002-11-08 00:00:00adminsetstatus: open -> nad
2002-07-11 00:00:00admincreate