7d46ed1f0f5b0b419249c05eb76426331dc32fc4
[external/binutils.git] / gdb / testsuite / gdb.cp / impl-this.cc
1 /* This testcase is part of GDB, the GNU debugger.
2
3    Copyright 2013-2018 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 #ifdef DEBUG
19 #include <stdio.h>
20 #endif
21
22 template <typename T>
23 class A
24 {
25 public:
26   T i;
27   T z;
28   A () : i (1), z (10) {}
29 };
30
31 template <typename T>
32 class B : public virtual A<T>
33 {
34 public:
35   T i;
36   T common;
37   B () : i (2), common (200) {}
38 };
39
40 typedef B<int> Bint;
41
42 class C : public virtual A<int>
43 {
44 public:
45   int i;
46   int c;
47   int common;
48   C () : i (3), c (30), common (300) {}
49 };
50
51 class BB : public A<int>
52 {
53 public:
54   int i;
55   BB () : i (20) {}
56 };
57
58 class CC : public A<int>
59 {
60 public:
61   int i;
62   CC () : i (30) {}
63 };
64
65 class Ambig : public BB, public CC
66 {
67 public:
68   int i;
69   Ambig () : i (1000) {}
70 };
71
72 class D : public Bint, public C
73 {
74 public:
75   int i;
76   int x;
77   Ambig am;
78   D () : i (4), x (40) {}
79
80 #ifdef DEBUG
81 #define SUM(X)                                  \
82   do                                            \
83     {                                           \
84       sum += (X);                               \
85       printf ("" #X " = %d\n", (X));            \
86     }                                           \
87   while (0)
88 #else
89 #define SUM(X) sum += (X)
90 #endif
91
92 int
93 f (void)
94   {
95     int sum = 0;
96
97     SUM (i);
98     SUM (D::i);
99     SUM (D::B<int>::i);
100     SUM (B<int>::i);
101     SUM (D::C::i);
102     SUM (C::i);
103     SUM (D::B<int>::A<int>::i);
104     SUM (B<int>::A<int>::i);
105     SUM (A<int>::i);
106     SUM (D::C::A<int>::i);
107     SUM (C::A<int>::i);
108     SUM (D::x);
109     SUM (x);
110     SUM (D::C::c);
111     SUM (C::c);
112     SUM (c);
113     SUM (D::A<int>::i);
114     SUM (Bint::i);
115     //SUM (D::Bint::i);
116     //SUM (D::Bint::A<int>::i);
117     SUM (Bint::A<int>::i);
118     // ambiguous: SUM (common);
119     SUM (B<int>::common);
120     SUM (C::common);
121     SUM (am.i);
122     // ambiguous: SUM (am.A<int>::i);
123
124     return sum;
125   }
126 };
127
128 int
129 main (void)
130 {
131   Bint b;
132   D d;
133
134   return d.f () + b.i;
135 }