Topic: Defect Report: Self-initialization of UDT


Author: loewis@informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=)
Date: Mon, 15 Jul 2002 12:56:43 CST
Raw View
Francis Glassborow <francis.glassborow@ntlworld.com> writes:

> >Note, that { int a=a; } is pretty legal.
>
> No, AFAIK it has undefined behaviour. That means that it is
> syntactically OK but not semantically.

More precisely, it means that it is well-formed but has undefined
behaviour. People usually mean "well-formed" when they say "legal".
Not sure what "pretty legal" is.

Regards,
Martin

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Sergey P. Derevyago" <non-existent@iobox.com>
Date: 12 Jul 2002 16:06:30 GMT
Raw View
[ Note: forwarded to C++ Committee. -sdc ]

Section: 12.6.1 [class.expl.init]
Submitter: Sergey P. Derevyago

1. Is the following code well-formed?

 struct A { /* */ };

 int main()
 {
  A a=a;
 }

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

2. 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).
--
         With all respect, Sergey.          http://cpp3.virtualave.net/
         mailto : ders at skeptik.net



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Sat, 13 Jul 2002 14:33:52 GMT
Raw View
In article <3D2DE647.82F9F206@iobox.com>, Sergey P. Derevyago
<non-existent@iobox.com> writes
>[ Note: forwarded to C++ Committee. -sdc ]
>
>Section: 12.6.1 [class.expl.init]
>Submitter: Sergey P. Derevyago
>
>1. Is the following code well-formed?
>
> struct A { /* */ };
>
> int main()
> {
>  A a=a;
> }
>
>Note, that { int a=a; } is pretty legal.

No, AFAIK it has undefined behaviour. That means that it is
syntactically OK but not semantically.

The same applies to the case for UDTs except that it is possible to
remove the undefined behaviour. We have considered this many times in
the past. Indeed in about 93/4 I actually had a proposal to make your
UDT case ill-formed but withdrew it when it became clear that like it or
not there was code that could use that declaration. Whether it has UB or
not depends on how the copy ctor is written.

>
>2. 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).

--
Francis Glassborow      ACCU
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]