aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.cp
diff options
context:
space:
mode:
authorSami Wagiaalla <swagiaal@redhat.com>2010-06-07 16:11:35 +0000
committerSami Wagiaalla <swagiaal@redhat.com>2010-06-07 16:11:35 +0000
commit4c3376c84943b8102da4237141dab7f1595912ca (patch)
treefc4936a3a61d60b2a60379e534e7081099969bb2 /gdb/testsuite/gdb.cp
parent0f32ea4ce3309801590068305e7c8d7aeb495f2f (diff)
downloadgdb-4c3376c84943b8102da4237141dab7f1595912ca.zip
gdb-4c3376c84943b8102da4237141dab7f1595912ca.tar.gz
gdb-4c3376c84943b8102da4237141dab7f1595912ca.tar.bz2
Test and support all cpp operator types.
2010-06-07 Sami Wagiaalla <swagiaal@redhat.com> * value.h: Created oload_search_type enum. (find_overload_match): Use oload_search_type enum. * valops.c (find_overload_match): Support combined member and non-member search. * eval.c (evaluate_subexp_standard): Calls to find_overload_match now use oload_search_type enum. (oload_method_static): Verify index is a proper value. * valarith.c (value_user_defined_cpp_op): Search for and handle both member and non-member operators. (value_user_defined_cpp_op): New function. (value_user_defined_op): New function. (value_x_unop): Use value_user_defined_op. (value_x_binop): Ditto. * cp-support.c (make_symbol_overload_list_using): Added block iteration. Add check for namespace aliases and imported declarations. 2010-06-07 Sami Wagiaalla <swagiaal@redhat.com> * gdb.cp/koenig.exp: Test for ADL operators. * gdb.cp/koenig.cc: Added ADL operators. * gdb.cp/operator.exp: New test. * gdb.cp/operator.cc: New test.
Diffstat (limited to 'gdb/testsuite/gdb.cp')
-rw-r--r--gdb/testsuite/gdb.cp/koenig.cc54
-rw-r--r--gdb/testsuite/gdb.cp/koenig.exp36
-rw-r--r--gdb/testsuite/gdb.cp/operator.cc195
-rw-r--r--gdb/testsuite/gdb.cp/operator.exp58
4 files changed, 328 insertions, 15 deletions
diff --git a/gdb/testsuite/gdb.cp/koenig.cc b/gdb/testsuite/gdb.cp/koenig.cc
index fb4ecb1..c91dbf9 100644
--- a/gdb/testsuite/gdb.cp/koenig.cc
+++ b/gdb/testsuite/gdb.cp/koenig.cc
@@ -175,6 +175,7 @@ typedef O::A TOA;
typedef TOA TTOA;
//------------
+
static union {
int a;
char b;
@@ -182,6 +183,49 @@ static union {
//------------
+namespace P {
+ class Q{
+ public:
+ int operator== (int)
+ {
+ return 24;
+ }
+
+ int operator== (float)
+ {
+ return 25;
+ }
+
+ int operator+ (float)
+ {
+ return 26;
+ }
+
+ };
+
+ int operator!= (Q, int)
+ {
+ return 27;
+ }
+
+ int operator!= (Q, double)
+ {
+ return 28;
+ }
+
+ int operator+ (Q, int)
+ {
+ return 29;
+ }
+
+ int operator++ (Q)
+ {
+ return 30;
+ }
+}
+
+//------------
+
int
main ()
{
@@ -245,6 +289,16 @@ main ()
TTOA ttoa;
foo (ttoa, 'a');
+ P::Q q;
+ q == 5;
+ q == 5.0f;
+ q != 5;
+ q != 5.0f;
+ q + 5;
+ q + 5.0f;
+
+ ++q;
+
return first (0, c) + foo (eo) +
foo (eo, eo) + foo (eo, eo, 1) +
foo (fo, eo) + foo (1 ,fo, eo) +
diff --git a/gdb/testsuite/gdb.cp/koenig.exp b/gdb/testsuite/gdb.cp/koenig.exp
index 57be745..d5e6c3f 100644
--- a/gdb/testsuite/gdb.cp/koenig.exp
+++ b/gdb/testsuite/gdb.cp/koenig.exp
@@ -13,25 +13,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-if $tracelevel then {
- strace $tracelevel
-}
-
set testfile koenig
set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
- untested "Couldn't compile test program"
- return -1
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug c++}] } {
+ return -1
}
-# Get things started.
-
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
############################################
if ![runto_main] then {
@@ -109,3 +96,22 @@ gdb_test "p foo(ttoa, 'a')" "= 23"
#test that lookup is not thwarted by anonymous types
gdb_test "p foo (p_union)" \
"Cannot resolve function foo to any overloaded instance"
+
+# test lookup of namespace user-defined operators
+# and overload resolution:
+
+# within class
+gdb_test "p q == 5" "= 24"
+gdb_test "p q == 5.0f" "= 25"
+
+# within namespace
+gdb_test "p q != 5" "= 27"
+gdb_test "p q != 5.0f" "= 28"
+
+# across namespace and class
+gdb_test "p q + 5.0f" "= 26"
+gdb_test "p q + 5" "= 29"
+
+# some unary operators for good measure
+# Cannot resolve function operator++ to any overloaded instance
+gdb_test "p ++q" "= 30"
diff --git a/gdb/testsuite/gdb.cp/operator.cc b/gdb/testsuite/gdb.cp/operator.cc
new file mode 100644
index 0000000..cc925a0
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/operator.cc
@@ -0,0 +1,195 @@
+class A
+{
+};
+
+int operator== (A, int)
+{
+ return 11;
+}
+
+int operator== (A, char)
+{
+ return 12;
+}
+
+//------------------
+
+namespace B
+{
+ class C
+ {
+ };
+
+ int operator== (C, int)
+ {
+ return 22;
+ }
+
+ int operator== (C, char)
+ {
+ return 23;
+ }
+
+ namespace BD
+ {
+ int operator== (C, int)
+ {
+ return 24;
+ }
+ }
+}
+
+//------------------
+
+class D
+{
+};
+namespace
+{
+ int operator== (D, int)
+ {
+ return 33;
+ }
+
+ int operator== (D, char)
+ {
+ return 34;
+ }
+}
+
+int operator== (D, float)
+{
+ return 35;
+}
+
+//------------------
+
+class E
+{
+};
+namespace F
+{
+ int operator== (E, int)
+ {
+ return 44;
+ }
+
+ int operator== (E, char)
+ {
+ return 45;
+ }
+}
+
+int operator== (E, float)
+{
+ return 46;
+}
+
+using namespace F;
+
+//-----------------
+
+class G
+{
+public:
+ int operator== (int)
+ {
+ return 55;
+ }
+};
+
+int operator== (G, char)
+{
+ return 56;
+}
+
+//------------------
+
+class H
+{
+};
+namespace I
+{
+ int operator== (H, int)
+ {
+ return 66;
+ }
+}
+
+namespace ALIAS = I;
+
+//------------------
+
+class J
+{
+};
+
+namespace K
+{
+ int i;
+ int operator== (J, int)
+ {
+ return 77;
+ }
+}
+
+using K::i;
+
+//------------------
+
+class L
+{
+};
+namespace M
+{
+ int operator== (L, int)
+ {
+ return 88;
+ }
+}
+
+namespace N
+{
+ using namespace M;
+}
+
+using namespace N;
+
+//------------------
+
+int main ()
+{
+ A a;
+ a == 1;
+ a == 'a';
+
+ B::C bc;
+ bc == 1;
+ bc == 'a';
+ B::BD::operator== (bc,'a');
+
+ D d;
+ d == 1;
+ d == 'a';
+ d == 1.0f;
+
+ E e;
+ e == 1;
+ e == 'a';
+ e == 1.0f;
+
+ G g;
+ g == 1;
+ g == 'a';
+
+ H h;
+ I::operator== (h, 1);
+
+ J j;
+ K::operator== (j, 1);
+
+ L l;
+ l == 1;
+
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.cp/operator.exp b/gdb/testsuite/gdb.cp/operator.exp
new file mode 100644
index 0000000..ac89d2b
--- /dev/null
+++ b/gdb/testsuite/gdb.cp/operator.exp
@@ -0,0 +1,58 @@
+# Copyright 2008 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/>.
+
+set testfile operator
+set srcfile ${testfile}.cc
+if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug c++}] } {
+ return -1
+}
+
+############################################
+
+if ![runto_main] then {
+ perror "couldn't run to breakpoint main"
+ continue
+}
+
+# Test global operator
+gdb_test "p a == 1" "= 11" "global operator"
+gdb_test "p a == 'a'" "= 12" "global operator overload"
+
+# Test ADL operator
+gdb_test "p bc == 1" "= 22" "ADL operator"
+gdb_test "p bc == 'a'" "= 23" "ADL operator overload"
+gdb_test "p B::BD::operator== (bc,'a')" "= 24" "Fully qualified explicit operator call"
+
+# Test operator imported from anonymous namespace
+gdb_test "p d == 1" "= 33" "anonymous namespace operator"
+gdb_test "p d == 'a'" "= 34" "anonymous namespace operator overload"
+gdb_test "p d == 1.0f" "= 35" "anonymous namespace operator overload float"
+
+# Test operator imported by using directive
+gdb_test "p e == 1" "= 44" "imported operator"
+gdb_test "p e == 'a'" "= 45" "imported operator overload"
+gdb_test "p e == 1.0f" "= 46" "imported operator overload float"
+
+# Test member operator
+gdb_test "p g == 1" "= 55" "member operator"
+gdb_test "p g == 'a'" "= 56" "member operator overload"
+
+# Test that operators are not wrongly imported
+# by import declarations and namespace aliases
+gdb_test "p h == 1" "Cannot resolve function operator== to any overloaded instance" "namespace alias"
+gdb_test "p j == 1" "Cannot resolve function operator== to any overloaded instance" "imported declaration"
+
+# Test that indirectly imported operators work
+gdb_test "p l == 1" "= 88"