FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.bugs / 900520_06.C
blob2fda6cacc957324070bd44836376ea0fe8a36aab
1 // g++ 1.37.1 bug 900520_06
3 // When an object of a class type is passed into a formal parameter of the
4 // same class type (in a function call) the language definition calls for
5 // this action to be treated like any other form of an initialization of
6 // an object of the given class type.
8 // g++ fails however to invoke the (compiler-supplied) copy constructor for
9 // the class type when a parameter of the class type is passed as an
10 // actual parameter.
12 // This causes the following program to exit with a nonzero exit status.
14 // cfront 2.0 passes this test.
16 int base_copy_ctor_called = 0;
17 int member_copy_ctor_called = 0;
19 struct struct_0 {
20   struct_0 ();
21   struct_0 (const struct_0&);
24 struct_0::struct_0 ()
28 struct_0::struct_0 (const struct_0&)
30   base_copy_ctor_called++;
33 struct struct_1 {
34   struct_1 ();
35   struct_1 (const struct_1&);
38 struct_1::struct_1 ()
42 struct_1::struct_1 (const struct_1&)
44   member_copy_ctor_called++;
47 struct struct_2 : public struct_0 {
48   struct_2 ();
49   struct_1 struct_1_member;
50 #ifdef MAKE_COPY_CONSTRUCTOR_EXPLICIT
51   struct_2 (const struct_2&);
52 #endif
55 struct_2::struct_2 ()
59 #ifdef MAKE_COPY_CONSTRUCTOR_EXPLICIT
60 struct_2::struct_2 (const struct_2& arg) :
61   struct_0 ((struct_0&)arg),
62   struct_1_member (arg.struct_1_member)
65 #endif
67 void take_struct_2 (struct_2 arg)
71 int test ()
73   struct_2 struct_2_object0;
74   take_struct_2 (struct_2_object0);
75   return (base_copy_ctor_called != 1 || member_copy_ctor_called != 1);
78 int main () { return test (); }