1 // { dg-do run } 2 // g++ 1.37.1 bug 900520_06 3 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. 8 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. 12 13 // This causes the following program to exit with a nonzero exit status. 14 15 // cfront 2.0 passes this test. 16 17 int base_copy_ctor_called = 0; 18 int member_copy_ctor_called = 0; 19 20 struct struct_0 { 21 struct_0 (); 22 struct_0 (const struct_0&); 23 }; 24 struct_0()25struct_0::struct_0 () 26 { 27 } 28 struct_0(const struct_0 &)29struct_0::struct_0 (const struct_0&) 30 { 31 base_copy_ctor_called++; 32 } 33 34 struct struct_1 { 35 struct_1 (); 36 struct_1 (const struct_1&); 37 }; 38 struct_1()39struct_1::struct_1 () 40 { 41 } 42 struct_1(const struct_1 &)43struct_1::struct_1 (const struct_1&) 44 { 45 member_copy_ctor_called++; 46 } 47 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 54 }; 55 struct_2()56struct_2::struct_2 () 57 { 58 } 59 60 #ifdef MAKE_COPY_CONSTRUCTOR_EXPLICIT struct_2(const struct_2 & arg)61struct_2::struct_2 (const struct_2& arg) : 62 struct_0 ((struct_0&)arg), 63 struct_1_member (arg.struct_1_member) 64 { 65 } 66 #endif 67 take_struct_2(struct_2 arg)68void take_struct_2 (struct_2 arg) 69 { 70 } 71 test()72int test () 73 { 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); 77 } 78 main()79int main () { return test (); } 80