OSDN Git Service

Copyright updates for 2007.
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.cp / rtti1.cc
1 /* Code to go along with tests in rtti.exp.
2    
3    Copyright 2003, 2004, 2007 Free Software Foundation, Inc.
4
5    Contributed by David Carlton <carlton@bactrian.org> and by Kealia,
6    Inc.
7
8    This file is part of GDB.
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330,
23    Boston, MA 02111-1307, USA.  */
24
25 #include "rtti.h"
26
27 namespace n1 {
28
29   class C1;
30
31   class Base1 {
32   public:
33     virtual ~Base1() { }
34   };
35
36
37   class C1: public Base1 {
38   public:
39   };
40
41   class D1 : public C1{
42   public:
43     D1(C1 *, C1 *);
44     
45     C1* expr_1_;
46     C1* expr_2_;
47   };
48   
49   D1::D1(C1 *expr_1, C1 *expr_2)
50     : expr_1_(expr_1), expr_2_(expr_2) { }
51
52   C1 *create1() {
53     return new D1(0, 0);
54   }
55
56 } // n1
57
58 // NOTE: carlton/2004-01-23: This call exists only to convince GCC to
59 // keep around a reference to 'obj' in n2::func - GCC 3.4 had been
60 // optimizing it away.
61 void refer_to (n2::C2 *obj)
62 {
63   // Do nothing.
64 }
65
66 void refer_to (n2::n3::C3 *obj)
67 {
68   // Do nothing.
69 }
70
71 namespace n2
72 {
73   void func ()
74   {
75     C2 *obj = create2 ();
76
77     refer_to (obj);             // func-constructs-done
78
79     return;
80   }
81
82   namespace n3
83   {
84     void func3 ()
85     {
86       C3 *obj3 = create3 ();
87
88       refer_to (obj3);          // func3-constructs-done
89
90       return;
91     }
92   }
93 }
94
95 int main()
96 {
97     using namespace n1;
98     using namespace n2;
99
100     C1 *e1 = create1();
101     C2 *e2 = create2();
102
103     n2::func();                         // main-constructs-done
104     n2::n3::func3();
105
106     return 0;
107 }