17af5a897Schristos /* This testcase is part of GDB, the GNU debugger.
27af5a897Schristos
3*1424dfb3Schristos Copyright 2013-2020 Free Software Foundation, Inc.
47af5a897Schristos
57af5a897Schristos This program is free software; you can redistribute it and/or modify
67af5a897Schristos it under the terms of the GNU General Public License as published by
77af5a897Schristos the Free Software Foundation; either version 3 of the License, or
87af5a897Schristos (at your option) any later version.
97af5a897Schristos
107af5a897Schristos This program is distributed in the hope that it will be useful,
117af5a897Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
127af5a897Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137af5a897Schristos GNU General Public License for more details.
147af5a897Schristos
157af5a897Schristos You should have received a copy of the GNU General Public License
167af5a897Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */
177af5a897Schristos
187af5a897Schristos #ifdef DEBUG
197af5a897Schristos #include <stdio.h>
207af5a897Schristos #endif
217af5a897Schristos
227af5a897Schristos template <typename T>
237af5a897Schristos class A
247af5a897Schristos {
257af5a897Schristos public:
267af5a897Schristos T i;
277af5a897Schristos T z;
A()287af5a897Schristos A () : i (1), z (10) {}
297af5a897Schristos };
307af5a897Schristos
317af5a897Schristos template <typename T>
327af5a897Schristos class B : public virtual A<T>
337af5a897Schristos {
347af5a897Schristos public:
357af5a897Schristos T i;
367af5a897Schristos T common;
B()377af5a897Schristos B () : i (2), common (200) {}
387af5a897Schristos };
397af5a897Schristos
407af5a897Schristos typedef B<int> Bint;
417af5a897Schristos
427af5a897Schristos class C : public virtual A<int>
437af5a897Schristos {
447af5a897Schristos public:
457af5a897Schristos int i;
467af5a897Schristos int c;
477af5a897Schristos int common;
C()487af5a897Schristos C () : i (3), c (30), common (300) {}
497af5a897Schristos };
507af5a897Schristos
517af5a897Schristos class BB : public A<int>
527af5a897Schristos {
537af5a897Schristos public:
547af5a897Schristos int i;
BB()557af5a897Schristos BB () : i (20) {}
567af5a897Schristos };
577af5a897Schristos
587af5a897Schristos class CC : public A<int>
597af5a897Schristos {
607af5a897Schristos public:
617af5a897Schristos int i;
CC()627af5a897Schristos CC () : i (30) {}
637af5a897Schristos };
647af5a897Schristos
657af5a897Schristos class Ambig : public BB, public CC
667af5a897Schristos {
677af5a897Schristos public:
687af5a897Schristos int i;
Ambig()697af5a897Schristos Ambig () : i (1000) {}
707af5a897Schristos };
717af5a897Schristos
727af5a897Schristos class D : public Bint, public C
737af5a897Schristos {
747af5a897Schristos public:
757af5a897Schristos int i;
767af5a897Schristos int x;
777af5a897Schristos Ambig am;
D()787af5a897Schristos D () : i (4), x (40) {}
797af5a897Schristos
807af5a897Schristos #ifdef DEBUG
817af5a897Schristos #define SUM(X) \
827af5a897Schristos do \
837af5a897Schristos { \
847af5a897Schristos sum += (X); \
857af5a897Schristos printf ("" #X " = %d\n", (X)); \
867af5a897Schristos } \
877af5a897Schristos while (0)
887af5a897Schristos #else
897af5a897Schristos #define SUM(X) sum += (X)
907af5a897Schristos #endif
917af5a897Schristos
927af5a897Schristos int
f(void)937af5a897Schristos f (void)
947af5a897Schristos {
957af5a897Schristos int sum = 0;
967af5a897Schristos
977af5a897Schristos SUM (i);
987af5a897Schristos SUM (D::i);
997af5a897Schristos SUM (D::B<int>::i);
1007af5a897Schristos SUM (B<int>::i);
1017af5a897Schristos SUM (D::C::i);
1027af5a897Schristos SUM (C::i);
1037af5a897Schristos SUM (D::B<int>::A<int>::i);
1047af5a897Schristos SUM (B<int>::A<int>::i);
1057af5a897Schristos SUM (A<int>::i);
1067af5a897Schristos SUM (D::C::A<int>::i);
1077af5a897Schristos SUM (C::A<int>::i);
1087af5a897Schristos SUM (D::x);
1097af5a897Schristos SUM (x);
1107af5a897Schristos SUM (D::C::c);
1117af5a897Schristos SUM (C::c);
1127af5a897Schristos SUM (c);
1137af5a897Schristos SUM (D::A<int>::i);
1147af5a897Schristos SUM (Bint::i);
1157af5a897Schristos //SUM (D::Bint::i);
1167af5a897Schristos //SUM (D::Bint::A<int>::i);
1177af5a897Schristos SUM (Bint::A<int>::i);
1187af5a897Schristos // ambiguous: SUM (common);
1197af5a897Schristos SUM (B<int>::common);
1207af5a897Schristos SUM (C::common);
1217af5a897Schristos SUM (am.i);
1227af5a897Schristos // ambiguous: SUM (am.A<int>::i);
1237af5a897Schristos
1247af5a897Schristos return sum;
1257af5a897Schristos }
1267af5a897Schristos };
1277af5a897Schristos
1287af5a897Schristos int
main(void)1297af5a897Schristos main (void)
1307af5a897Schristos {
1317af5a897Schristos Bint b;
1327af5a897Schristos D d;
1337af5a897Schristos
1347af5a897Schristos return d.f () + b.i;
1357af5a897Schristos }
136