* hppa.h (pa_opcodes): Use "cX" completer instead of "cx" in fstqx
[external/binutils.git] / gdb / testsuite / gdb.cp / smartp.cc
1 /* This test script is part of GDB, the GNU debugger.
2
3    Copyright 1999, 2002-2012 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17    */
18
19 class Type1{
20   public:
21   int foo(){
22     return 11;
23   }
24 };
25
26 class Type2{
27   public:
28   int foo(){
29     return 22;
30   }
31 };
32
33 class Type3{
34   public:
35   int foo(int){
36     return 33;
37   }
38   int foo(char){
39     return 44;
40   }
41 };
42
43 class Type4 {
44   public:
45     int a;
46     int b;
47 };
48
49 int foo (Type3, float)
50 {
51   return 55;
52 }
53
54 class MyPointer{
55   Type1 *p;
56  public:
57   MyPointer(Type1 *pointer){
58     p = pointer;
59   }
60
61   Type1 *operator->(){
62     return p;
63   }
64 };
65
66 template <typename T> class SmartPointer{
67   T *p;
68  public:
69   SmartPointer(T *pointer){
70     p = pointer;
71   }
72
73   T *operator->(){
74     return p;
75   }
76 };
77
78
79 class A {
80  public:
81   int inta;
82   int foo() { return 66; }
83 };
84
85 class B {
86  public:
87   A a;
88   A* operator->(){
89     return &a;
90   }
91 };
92
93 class C {
94  public:
95   B b;
96   B& operator->(){
97     return b;
98   }
99 };
100
101 class C2 {
102  public:
103   B b;
104   B operator->(){
105     return b;
106   }
107 };
108
109 int main(){
110   Type1 mt1;
111   Type2 mt2;
112   Type3 mt3;
113
114   Type4 mt4;
115   mt4.a = 11;
116   mt4.b = 12;
117
118   MyPointer mp(&mt1);
119   Type1 *mtp = &mt1;
120
121   SmartPointer<Type1> sp1(&mt1);
122   SmartPointer<Type2> sp2(&mt2);
123   SmartPointer<Type3> sp3(&mt3);
124   SmartPointer<Type4> sp4(&mt4);
125
126   mp->foo();
127   mtp->foo();
128
129   sp1->foo();
130   sp2->foo();
131
132   sp3->foo(1);
133   sp3->foo('a');
134
135   sp4->a;
136   sp4->b;
137
138   Type4 *mt4p = &mt4;
139   mt4p->a;
140   mt4p->b;
141
142   A a;
143   B b;
144   C c;
145   C2 c2;
146
147   a.inta = 77;
148   b.a = a;
149   c.b = b;
150   c2.b = b;
151
152   a.foo();
153   b->foo();
154   c->foo();
155
156   b->inta = 77;
157   c->inta = 77;
158   c2->inta = 77;
159
160   return 0; // end of main
161 }
162