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