2018-02-09 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.brendan / copy8.C
blob096052342350e925e95d00155be0baacc69f9f3b
1 // { dg-do run  }
2 // GROUPS passed copy-ctors
3 /*
4 This report is for GCC 2.3.3 running on a Sun/4.  The bug is that when
5 a class instance is passed-by-value, GCC does not correctly copy the value.
6 At the end of this report is an example program that demonstrates the bug.  
7 It should print:
9         construct A('x')
10         copy A('x')
11         destruct A('x')
12         destruct A('x')
14 and in fact does for IBM's xlC C++.  However, for GCC 2.3.3, it fails
15 to print the second line ["copy A('x')"], which indicates that it failed
16 to call the copy-constructor for class A when it should have.  Below is a 
17 typescript that lists the program, shows how I compiled it, and shows the 
18 incorrect output.
21 extern "C" int printf (const char *, ...);
22 extern "C" void exit (int);
24 int count = 0;
26 void
27 die (int x)
29   if (x != ++count)
30     {
31       printf ("FAIL\n");
32       exit (1);
33     }
36 class A { // Class with explicit & instrumented copy-constructor and destructor.
37 public:
38     const char * id;
39     A( const char * id1 ) : id(id1) { die (1); }
41     // Copy constructor
42     A( const A& a ) : id(a.id) { die (2); }
44     // Destructor
45     ~A() { count++; if (count != 3 && count != 4) die (-1); }
48 class X { // Class without explicit copy-constructor
49 private:
50     A a;
51 public:
52     X( const char * id ) : a(id) {}
55 void Func( X x ) {      // Function with call-by-value argument
58 int
59 main() {
60     X x("x");           // Construct instance of x.
62     // The next line should call the copy-constructor for X since x is
63     // being passed by value.  For GCC 2.3.3 on a Sun/4, it does not.
64     Func(x);
66     printf ("PASS\n");
67     return 0;