c++/24367: Infinite recursion of typedef substitution
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / overload.exp
index b09c58e385904ebd0cecbd14e4b2aaaa445ea79b..a169419f79e4d2ccb75e8d89cf09c1be3b07b177 100644 (file)
@@ -1,19 +1,17 @@
-# Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
-# Free Software Foundation, Inc.
+# Copyright 1998-2019 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 2 of the License, or
+# 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, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # written by Elena Zannoni (ezannoni@cygnus.com)
 # Rewritten by Michael Chastain <mec.gnu@mindspring.com>
 
 # Tests for overloaded member functions.
 
-if $tracelevel then {
-    strace $tracelevel
-}
-
 set ws "\[\r\n\t \]+"
 set nl "\[\r\n\]+"
 
-set prms_id 0
-set bug_id 0
 
 if { [skip_cplus_tests] } { continue }
 
-set testfile "overload"
-set srcfile ${testfile}.cc
-set binfile ${objdir}/${subdir}/${testfile}
+standard_testfile .cc
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
-     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
+    return -1
 }
 
-gdb_exit
-gdb_start
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
 # Set it up at a breakpoint so we can play with the variable values.
 
 if ![runto 'marker1'] then {
@@ -54,6 +39,9 @@ if ![runto 'marker1'] then {
     continue
 }
 
+# Prevent symbol on address 0x0 being printed.
+gdb_test_no_output "set print symbol off"
+
 gdb_test "up" ".*main.*" "up from marker1"
 
 # Print the monster class type.
@@ -74,14 +62,16 @@ set re_methods      "${re_methods}${ws}int overload1arg\\((void|)\\);"
 set re_methods "${re_methods}${ws}int overload1arg\\(char\\);"
 set re_methods "${re_methods}${ws}int overload1arg\\(signed char\\);"
 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned char\\);"
-set re_methods "${re_methods}${ws}int overload1arg\\(short\\);"
-set re_methods "${re_methods}${ws}int overload1arg\\(unsigned short\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\(short( int)?\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\((unsigned short|short unsigned)( int)?\\);"
 set re_methods "${re_methods}${ws}int overload1arg\\(int\\);"
 set re_methods "${re_methods}${ws}int overload1arg\\(unsigned int\\);"
-set re_methods "${re_methods}${ws}int overload1arg\\(long\\);"
-set re_methods "${re_methods}${ws}int overload1arg\\(unsigned long\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\(long( int)?\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\((unsigned long|long unsigned)( int)?\\);"
 set re_methods "${re_methods}${ws}int overload1arg\\(float\\);"
 set re_methods "${re_methods}${ws}int overload1arg\\(double\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\(int \\*\\);"
+set re_methods "${re_methods}${ws}int overload1arg\\(void \\*\\);"
 set re_methods "${re_methods}${ws}int overloadfnarg\\((void|)\\);"
 set re_methods "${re_methods}${ws}int overloadfnarg\\(int\\);"
 set re_methods "${re_methods}${ws}int overloadfnarg\\(int, int ?\\(\\*\\) ?\\(int\\)\\);"
@@ -101,11 +91,6 @@ set re_synth        "foo & operator=\\(foo const ?&\\);"
 gdb_test "print foo_instance1" "\\$\[0-9\]+ = \{ifoo = 111, ccpfoo = 0x0\}"
 
 gdb_test_multiple "ptype foo_instance1" "ptype foo_instance1" {
-    -re "type = $re_class${ws}$re_fields${ws}$re_ctor${ws}$re_dtor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
-       # gcc 2.95.3 -gdwarf-2
-       # TODO: this is not a quirk!
-       pass "ptype foo_instance1 (HP aCC -- known quirk with ~foo parameter list)"
-    }
     -re "type = $re_class${ws}$XX_fields${ws}$re_synth${ws}$re_dtor${ws}$re_ctor${ws}$re_methods$nl\}$nl$gdb_prompt $" {
        # gcc 2.95.3 -gstabs+, no "const" on "const char *"
        # TODO: gdb.base/constvar.exp has XFAILed this kind of problem for a
@@ -152,6 +137,9 @@ gdb_test "print foo_instance3" "\\$\[0-9\]+ = \{ifoo = 222, ccpfoo = $hex \"A\"\
 gdb_test "print foo_instance1.overloadargs(1)" "\\$\[0-9\]+ = 1" \
     "print call overloaded func 1 arg"
 
+# Regression test for overloading with function pointer type.
+gdb_test "print foo_instance1.overloadfnarg(23, intintfunc)" " = 23"
+
 # If GDB fails to restore the selected frame properly after the
 # inferior function call above (see GDB PR 1155 for an explanation of
 # why this might happen), all the subsequent tests will fail.  We
@@ -258,14 +246,41 @@ gdb_test "print foo_instance1.overload1arg((double)arg12)" \
     "\\$\[0-9\]+ = 12" \
     "print call overloaded func double arg"
 
+gdb_test "print foo_instance1.overload1arg(&arg13)" \
+    "\\$\[0-9\]+ = 13" \
+    "print call overloaded func int\\* arg"
+
+gdb_test "print foo_instance1.overload1arg(&arg14)" \
+    "\\$\[0-9\]+ = 14" \
+    "print call overloaded func char\\* arg"
+
+gdb_test "print bar(a)" "= 11"
+gdb_test "print bar(b)" "= 22"
+gdb_test "print bar(c)" "= 22"
+gdb_test "print bar(d)" "= 22"
+
 # ---
 
 # List overloaded functions.
 
+gdb_test_no_output "set listsize 1" ""
+
+# Build source listing pattern based on an inclusive line range.
+
+proc line_range_pattern { range_start range_end } {
+    global line_re
+
+    for {set i $range_start} {$i <= $range_end} {incr i} {
+       append pattern "\r\n$i\[ \t\]\[^\r\n\]*"
+    }
+
+    verbose -log "pattern $pattern"
+    return $pattern
+}
+
 # The void case is tricky because some compilers say "(void)"
 # and some compilers say "()".
 
-gdb_test "set listsize 1" "" ""
 gdb_test_multiple "info func overloadfnarg" "list overloaded function with no args" {
     -re ".*overloadfnarg\\(void\\).*$gdb_prompt $" {
        # gcc 2
@@ -293,12 +308,54 @@ gdb_test "list \"foo::overloadfnarg(int, int (*)(int))\"" \
    "int foo::overloadfnarg.*\\(int arg, int \\(\\*foo\\) \\(int\\)\\).*" \
    "list overloaded function with function ptr args - quotes around argument"
 
+# Test list with filename.
+
+gdb_test "list ${srcfile}:intToChar" "int intToChar.*"
+gdb_test "list ${srcfile}:intToChar(char)" "int intToChar.*"
+gdb_test "list ${srcfile}:'intToChar(char)'" "int intToChar.*"
+gdb_test "list '${srcfile}:intToChar(char)'" "int intToChar.*"
+gdb_test "list '${srcfile}':intToChar(char)" "int intToChar.*"
+gdb_test "list '${srcfile}':'intToChar(char)'" "int intToChar.*"
+
+# And with filename and namespace.
+
+gdb_test "list ${srcfile}:foo::overloadfnarg(int)" "int foo::overloadfnarg.*}"
+gdb_test "list ${srcfile}:'foo::overloadfnarg(int)'" "int foo::overloadfnarg.*}"
+
 # Now some tests to see how overloading and namespaces interact.
 
 gdb_test "print overloadNamespace(1)" ".\[0-9\]* = 1"
 gdb_test "print overloadNamespace('a')" ".\[0-9\]* = 1"
 gdb_test "print overloadNamespace(dummyInstance)" ".\[0-9\]* = 2"
 
+# Static methods.
+gdb_test "print K::staticoverload ()" " = 1"
+gdb_test "print K::staticoverload (2)" " = 2"
+gdb_test "print K::staticoverload (2, 3)" " = 5"
+
+# Namespace-qualified functions.
+gdb_test "print N::nsoverload ()" " = 1"
+gdb_test "print N::nsoverload (2)" " = 2"
+gdb_test "print N::nsoverload (2, 3)" " = 5"
+
+# Test "list function" when there are multiple "function" overloads.
+
+with_test_prefix "list all overloads" {
+    # Bump up listsize again, to make sure the number of lines to
+    # display before/after each location is computed correctly.
+    gdb_test_no_output "set listsize 10"
+
+    set line_bar_A [gdb_get_line_number "int bar (A)"]
+    set line_bar_B [gdb_get_line_number "int bar (B)"]
+    set lines1 [line_range_pattern [expr $line_bar_A - 5] [expr $line_bar_A + 4]]
+    set lines2 [line_range_pattern [expr $line_bar_B - 5] [expr $line_bar_B + 4]]
+
+    set any "\[^\r\n\]*"
+    set h1_re "file: \"${any}overload.cc\", line number: $line_bar_A, symbol: \"bar\\(A\\)\""
+    set h2_re "file: \"${any}overload.cc\", line number: $line_bar_B, symbol: \"bar\\(B\\)\""
+    gdb_test "list bar" "${h1_re}${lines1}\r\n${h2_re}${lines2}"
+}
+
 if ![runto 'XXX::marker2'] then {
     perror "couldn't run to XXX::marker2"
     continue
@@ -312,3 +369,24 @@ gdb_test "print overloadNamespace(dummyInstance)" ".\[0-9\]* = 2" "print overloa
 # I wonder what this is for?
 
 gdb_test "print intToChar(1)" "\\$\[0-9\]+ = 297"
+
+# Test expression evaluation with overloaded methods
+gdb_test "print foo::overload1arg" \
+    "non-unique member `overload1arg' requires type instantiation" \
+    "print foo::overload1arg"
+
+gdb_test "print foo::overload1arg(char***)" \
+    "no member function matches that type instantiation" \
+    "print foo::overload1arg(char***)"
+
+gdb_test "print foo::overload1arg(void)" \
+    "\\$$decimal = {int \\(foo \\*( const|)\\)} $hex <foo::overload1arg\\(\\)>" \
+    "print foo::overload1arg(void)"
+
+foreach t [list char "signed char" "unsigned char" "short" \
+              "unsigned short" int "unsigned int" long "unsigned long" \
+              float double] {
+    gdb_test "print foo::overload1arg($t)" \
+       "\\$$decimal = {int \\(foo \\*( const|), $t\\)} $hex <foo::overload1arg\\($t\\)>" \
+       "print foo::overload1arg($t)"
+}
This page took 0.029528 seconds and 4 git commands to generate.