2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.bugs / 900520_06.C
blobe111231931734a2e03a53fe7ee3d0852f0586d07
1 // { dg-do run  }
2 // g++ 1.37.1 bug 900520_06
4 // When an object of a class type is passed into a formal parameter of the
5 // same class type (in a function call) the language definition calls for
6 // this action to be treated like any other form of an initialization of
7 // an object of the given class type.
9 // g++ fails however to invoke the (compiler-supplied) copy constructor for
10 // the class type when a parameter of the class type is passed as an
11 // actual parameter.
13 // This causes the following program to exit with a nonzero exit status.
15 // cfront 2.0 passes this test.
17 int base_copy_ctor_called = 0;
18 int member_copy_ctor_called = 0;
20 struct struct_0 {
21   struct_0 ();
22   struct_0 (const struct_0&);
25 struct_0::struct_0 ()
29 struct_0::struct_0 (const struct_0&)
31   base_copy_ctor_called++;
34 struct struct_1 {
35   struct_1 ();
36   struct_1 (const struct_1&);
39 struct_1::struct_1 ()
43 struct_1::struct_1 (const struct_1&)
45   member_copy_ctor_called++;
48 struct struct_2 : public struct_0 {
49   struct_2 ();
50   struct_1 struct_1_member;
51 #ifdef MAKE_COPY_CONSTRUCTOR_EXPLICIT
52   struct_2 (const struct_2&);
53 #endif
56 struct_2::struct_2 ()
60 #ifdef MAKE_COPY_CONSTRUCTOR_EXPLICIT
61 struct_2::struct_2 (const struct_2& arg) :
62   struct_0 ((struct_0&)arg),
63   struct_1_member (arg.struct_1_member)
66 #endif
68 void take_struct_2 (struct_2 arg)
72 int test ()
74   struct_2 struct_2_object0;
75   take_struct_2 (struct_2_object0);
76   return (base_copy_ctor_called != 1 || member_copy_ctor_called != 1);
79 int main () { return test (); }