1/* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2013-2023 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 22template <typename T> 23class A 24{ 25public: 26 T i; 27 T z; 28 A () : i (1), z (10) {} 29}; 30 31template <typename T> 32class B : public virtual A<T> 33{ 34public: 35 T i; 36 T common; 37 B () : i (2), common (200) {} 38}; 39 40typedef B<int> Bint; 41 42class C : public virtual A<int> 43{ 44public: 45 int i; 46 int c; 47 int common; 48 C () : i (3), c (30), common (300) {} 49}; 50 51class BB : public A<int> 52{ 53public: 54 int i; 55 BB () : i (20) {} 56}; 57 58class CC : public A<int> 59{ 60public: 61 int i; 62 CC () : i (30) {} 63}; 64 65class Ambig : public BB, public CC 66{ 67public: 68 int i; 69 Ambig () : i (1000) {} 70}; 71 72class D : public Bint, public C 73{ 74public: 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 92int 93f (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 128int 129main (void) 130{ 131 Bint b; 132 D d; 133 134 return d.f () + b.i; 135} 136