diff options
Diffstat (limited to 'gdb/testsuite/gdb.cp')
-rw-r--r-- | gdb/testsuite/gdb.cp/impl-this.cc | 135 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/impl-this.exp | 130 |
2 files changed, 265 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.cp/impl-this.cc b/gdb/testsuite/gdb.cp/impl-this.cc new file mode 100644 index 0000000..6be0ddf --- /dev/null +++ b/gdb/testsuite/gdb.cp/impl-this.cc @@ -0,0 +1,135 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2013 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef DEBUG +#include <stdio.h> +#endif + +template <typename T> +class A +{ +public: + T i; + T z; + A () : i (1), z (10) {} +}; + +template <typename T> +class B : public virtual A<T> +{ +public: + T i; + T common; + B () : i (2), common (200) {} +}; + +typedef B<int> Bint; + +class C : public virtual A<int> +{ +public: + int i; + int c; + int common; + C () : i (3), c (30), common (300) {} +}; + +class BB : public A<int> +{ +public: + int i; + BB () : i (20) {} +}; + +class CC : public A<int> +{ +public: + int i; + CC () : i (30) {} +}; + +class Ambig : public BB, public CC +{ +public: + int i; + Ambig () : i (1000) {} +}; + +class D : public Bint, public C +{ +public: + int i; + int x; + Ambig am; + D () : i (4), x (40) {} + +#ifdef DEBUG +#define SUM(X) \ + do \ + { \ + sum += (X); \ + printf ("" #X " = %d\n", (X)); \ + } \ + while (0) +#else +#define SUM(X) sum += (X) +#endif + +int +f (void) + { + int sum = 0; + + SUM (i); + SUM (D::i); + SUM (D::B<int>::i); + SUM (B<int>::i); + SUM (D::C::i); + SUM (C::i); + SUM (D::B<int>::A<int>::i); + SUM (B<int>::A<int>::i); + SUM (A<int>::i); + SUM (D::C::A<int>::i); + SUM (C::A<int>::i); + SUM (D::x); + SUM (x); + SUM (D::C::c); + SUM (C::c); + SUM (c); + SUM (D::A<int>::i); + SUM (Bint::i); + //SUM (D::Bint::i); + //SUM (D::Bint::A<int>::i); + SUM (Bint::A<int>::i); + // ambiguous: SUM (common); + SUM (B<int>::common); + SUM (C::common); + SUM (am.i); + // ambiguous: SUM (am.A<int>::i); + + return sum; + } +}; + +int +main (void) +{ + Bint b; + D d; + + return d.f () + b.i; +} diff --git a/gdb/testsuite/gdb.cp/impl-this.exp b/gdb/testsuite/gdb.cp/impl-this.exp new file mode 100644 index 0000000..ce7c780 --- /dev/null +++ b/gdb/testsuite/gdb.cp/impl-this.exp @@ -0,0 +1,130 @@ +# Copyright 2013 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This file is part of the gdb testsuite + +# Test expressions which assume an implicit "this" with a qualified +# name. + +if {[skip_cplus_tests]} { continue } + +standard_testfile .cc + +if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} { + return -1 +} + +# First test expressions when there is no context. +with_test_prefix "before run" { + gdb_test "print i" "No symbol \"i\" in current context." + gdb_test "print D::i" "Cannot reference non-static field \"i\"" + gdb_test "print D::B<int>::i" "Cannot reference non-static field \"i\"" + gdb_test "print B<int>::i" "Cannot reference non-static field \"i\"" + gdb_test "print D::C::i" "Cannot reference non-static field \"i\"" + gdb_test "print C::i" "Cannot reference non-static field \"i\"" + gdb_test "print D::B<int>::A<int>::i" \ + "Cannot reference non-static field \"i\"" + gdb_test "print B<int>::A<int>::i" "Cannot reference non-static field \"i\"" + gdb_test "print A<int>::i" "Cannot reference non-static field \"i\"" + gdb_test "print D::C::A<int>::i" "Cannot reference non-static field \"i\"" + gdb_test "print C::A<int>::i" "Cannot reference non-static field \"i\"" + gdb_test "print D::x" "Cannot reference non-static field \"x\"" + gdb_test "print x" "No symbol \"x\" in current context." + gdb_test "print D::C::c" "Cannot reference non-static field \"c\"" + gdb_test "print C::c" "Cannot reference non-static field \"c\"" + gdb_test "print c" "No symbol \"c\" in current context." + gdb_test "print D::A<int>::i" "Cannot reference non-static field \"i\"" +} + +# Run to D::f. +if {![runto_main]} { + perror "couldn't run to main" + continue +} + +gdb_breakpoint "D::f" +gdb_continue_to_breakpoint "continue to D::f" + +# Now test valid expressions in the class hierarchy for D. +with_test_prefix "at D::f (valid expressions)" { + gdb_test "print i" "= 4" + gdb_test "print D::i" "= 4" + gdb_test "print D::B<int>::i" "= 2" + gdb_test "print B<int>::i" "= 2" + gdb_test "print D::Bint::i" \ + "No type \"Bint\" within class or namespace \"D\"." + gdb_test "print Bint::i" "= 2" + gdb_test "print D::C::i" "= 3" + gdb_test "print C::i" "= 3" + gdb_test "print D::B<int>::A<int>::i" "= 1" + gdb_test "print B<int>::A<int>::i" "= 1" + gdb_test "print D::Bint::A<int>::i" \ + "No type \"Bint\" within class or namespace \"D\"." + gdb_test "print Bint::A<int>::i" "= 1" + gdb_test "print A<int>::i" "= 1" + gdb_test "print D::C::A<int>::i" "= 1" + gdb_test "print C::A<int>::i" "= 1" + gdb_test "print D::x" "= 40" + gdb_test "print x" "= 40" + gdb_test "print D::C::c" "= 30" + gdb_test "print C::c" "= 30" + gdb_test "print c" "= 30" + gdb_test "print D::A<int>::i" "= 1" +} + +# Test some invalid expressions +with_test_prefix "at D::f (invalid expressions)" { + gdb_test "print D::B<int>::c" "There is no field named c" + gdb_test "print D::B<int>::A<int>::c" "There is no field named c" + gdb_test "print D::Bint::c" \ + "No type \"Bint\" within class or namespace \"D\"." + + gdb_test "print D::Bint::A<int>::c" \ + "No type \"Bint\" within class or namespace \"D\"." + gdb_test "print D::C::A<int>::c" "There is no field named c" + gdb_test "print B<int>::c" "There is no field named c" + gdb_test "print B<int>::A<int>::c" "There is no field named c" + gdb_test "print Bint::c" "There is no field named c" + gdb_test "print Bint::A<int>::c" "There is no field named c" + gdb_test "print C::A<int>::c" "There is no field named c" + gdb_test "print D::B<int>::x" "There is no field named x" + gdb_test "print D::B<int>::A<int>::x" "There is no field named x" + gdb_test "print D::Bint::x" \ + "No type \"Bint\" within class or namespace \"D\"." + gdb_test "print D::Bint::A<int>::x" \ + "No type \"Bint\" within class or namespace \"D\"." + gdb_test "print B<int>::x" "There is no field named x" + gdb_test "print B<int>::A<int>::x" "There is no field named x" + gdb_test "print Bint::x" "There is no field named x" + gdb_test "print Bint::A<int>::x" "There is no field named x" + gdb_test "print D::C::x" "There is no field named x" + gdb_test "print C::x" "There is no field named x" + gdb_test "print D::C::A<int>::x" "There is no field named x" + gdb_test "print C::A<int>::x" "There is no field named x" +} + +# Test some ambiguous names +with_test_prefix "at D::f (ambiguous names)" { + gdb_test "print B<int>::common" " = 200" + gdb_test "print Bint::common" " = 200" + gdb_test "print C::common" " = 300" + gdb_test "print am.i" " = 1000" + gdb_test "print am.A<int>::i" \ + "base class 'A<int>' is ambiguous in type 'Ambig'" + gdb_test "print am.BB::A<int>::i" \ + "base class 'A<int>' is ambiguous in type 'Ambig'" + gdb_test "print am.CC::A<int>::i" \ + "base class 'A<int>' is ambiguous in type 'Ambig'" +} |