[comp.lang.c++] recursive memberwise initialisation

leo@atcmp.nl (Leo Willems) (07/06/90)

The next program calls a default constructor at an unexpected place, 
I think it is a bug.

=================
struct A{
	A(){ puts("I am default constructor A()"); }
};
	
struct B{
	B() { puts("I am default constructor B()"); }
	B(B&){  puts("I am copy constructor B(B&)"); }
};

struct C{
	C(){ puts("I am default constructor C()");}
	A a;
	B b;
};

main()
{
	puts(" first a 'default' constructor:");
	C defc;

	puts("\n now a  copy constructor: ");
	C copc(defc);
}
======outputs:  (after compilation with Glsp. 2.0 for sparc station):
 first a 'default' constructor:
I am default constructor A()
I am default constructor B()
I am default constructor C()

 now a  copy constructor: 
I am default constructor A()		<===== offending constructor call
I am copy constructor B(B&)
===============================

This is the first reason why I think this is a bug:
The A() constructor is used on the A part of variable copc,( not on
some temporary) so the A part of copc is first initialised using
A::A(), THEN overwitten using the default memberwise initialisation.
(In practice, this will not often lead to an error)

This is the second reason why I think this is a bug:
When in class C the declarations of the members A and B are switched
the `error' is gone, the output becomes:
================
 first a 'default' constructor:
I am default constructor B()
I am default constructor A()
I am default constructor C()

 now a  copy constructor: 
I am copy constructor B(B&)
===============
 
Is this fixed in 2.1? (If it's a bug......)

Thanks

Leo


 Leo Willems			Internet: leo@atcmp.nl
 AT Computing			UUCP:     mcsun!hp4nl!kunivv1!atcmpe!leo
 P. O. Box 1428				
 6501 BK  Nijmegen		Phone:    +31-80-566880
 The Netherlands		Fax:	  +31-80-555887