OSDN Git Service

fix
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.other / op3.C
1 // Copyright (C) 2000, 2001 Free Software Foundation, Inc.
2 // Contributed by Nathan Sidwell 28 Nov 2000 <nathan@codesourcery.com>
3
4 // Related to bug 91. We'd not preserve constness accessing a member of the
5 // source type in copy ctor and assignment op.
6
7 #include <stdio.h>
8
9 int value = 0;
10
11 struct A
12 {
13   A() {}
14
15   A( A& arg) 
16   { printf ("%s\n", __PRETTY_FUNCTION__); value = 1;}
17
18   A( const A& arg)
19   { printf ("%s\n", __PRETTY_FUNCTION__); value = 2;}
20
21   A& operator=( A& ) 
22   { printf ("%s\n", __PRETTY_FUNCTION__); value = 3; return *this; }
23
24   A& operator=( const A& ) 
25   { printf ("%s\n", __PRETTY_FUNCTION__); value = 4; return *this; }
26 };
27
28 struct B
29 {
30   A a;
31   B () {}
32 };
33
34 void foo( A& )
35 {
36   printf ("%s\n", __PRETTY_FUNCTION__); value = 5;
37 }
38
39 void foo( const A& )
40 {
41  printf ("%s\n", __PRETTY_FUNCTION__); value = 6;
42 }
43
44 int main()
45 {
46   const A a0;
47   value = 0; printf ("A(cA) : ");  A a1(a0); if (value != 2) return 1;
48   value = 0; printf ("A(A ) : ");  A a2(a1); if (value != 1) return 2;
49   
50   const B b0;
51   value = 0; printf ("B(cB) : ");  B b1(b0); if (value != 2) return 3;
52   value = 0; printf ("B(B ) : ");  B b2(b1); if (value != 2) return 4;
53
54   value = 0; printf ("A= cA : ");  a1 = a0; if (value != 4) return 5;
55   value = 0; printf ("A= A : ");   a1 = a2; if (value != 3) return 6;
56   value = 0; printf ("B= cB : ");  b1 = b0; if (value != 4) return 7;
57   value = 0; printf ("B= B : ");   b1 = b2; if (value != 4) return 8;
58
59   value = 0; printf ("foo(cB): "); foo(b0.a); if (value != 6) return 9;
60   value = 0; printf ("foo(B ): "); foo(b2.a); if (value != 5) return 10;
61
62   return 0;
63 }