Home | History | Annotate | Line # | Download | only in gdb.cp
converts.exp revision 1.9.2.1
      1 # Copyright 2008-2023 Free Software Foundation, Inc.
      2 
      3 # This program is free software; you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation; either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15 
     16 standard_testfile .cc
     17 
     18 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug c++}] } {
     19      return -1
     20 }
     21 
     22 ############################################
     23 
     24 if {![runto_main]} {
     25     return
     26 }
     27 
     28 gdb_breakpoint [gdb_get_line_number "end of main"]
     29 gdb_continue_to_breakpoint "end of main"
     30 
     31 gdb_test "p foo0_1 (ta)"   "= 1"              "typedef to another typedef"
     32 gdb_test "p foo0_2 (ta)"   "= 2"              "typedef to typedef of a typedef"
     33 gdb_test "p foo0_3 (bppp)" "Cannot resolve.*" \
     34  "Pointer-to-pointer-to-pointer derived to Pointer-to-pointer-to-pointer base."
     35 
     36 gdb_test "p foo1_1 (a)"  "= 11"             "pointer to pointer"
     37 gdb_test "p foo1_2 (a)"  "= 12"             "pointer to array"
     38 gdb_test "p foo1_3 (a)"  "Cannot resolve.*" \
     39 	 "pointer to pointer of wrong type, a"
     40 gdb_test "p foo1_3 (bp)" "Cannot resolve.*" \
     41 	 "pointer to pointer of wrong type, bp"
     42 gdb_test "p foo1_4 (bp)" "= 14"             "pointer to ancestor pointer"
     43 gdb_test "p foo1_5 (bp)" "= 15"             "pointer to void pointer"
     44 gdb_test "p foo1_6 (bp)" "Cannot resolve.*"     "pointer to void pointer pointer"
     45 gdb_test "p foo1_7 (bp)" "= 17"                 "pointer to boolean"
     46 gdb_test "p foo1_8 (bp)" "Using non-standard.*" "pointer to long int"
     47 
     48 gdb_test "p foo1_5 (b)" "= 15"             "pointer pointer to void pointer"
     49 gdb_test "p foo2_1 (b)" "= 21"             "pointer pointer to pointer pointer"
     50 gdb_test "p foo2_2 (b)" "Cannot resolve.*" "pointer pointer to array of arrays"
     51 gdb_test "p foo2_3 (b)" "= 23"             "pointer pointer to array of pointers"
     52 gdb_test "p foo2_4 (b)" "Cannot resolve.*" "pointer pointer to array of wrong pointers"
     53 
     54 gdb_test "p foo3_1 ((char *) 0, ta)" "Cannot resolve.*" \
     55     "check all parameters for badness"
     56 
     57 # Tests for null pointer conversion
     58 global gdb_prompt
     59 set nl {[\r\n]+}
     60 set t "null pointer conversion"
     61 gdb_test_multiple "p foo3_1 (0, 0)" $t {
     62   -re "warning: Using non-standard conversion.*$nl$gdb_prompt $" {
     63     fail "$t (warning issued)"
     64   }
     65 
     66   -re "Cannot resolve function foo3_1 to any overloaded instance$nl$gdb_prompt $" {
     67     fail "$t (conversion failed)"
     68   }
     69 
     70   -re "\\$\[0-9\]+ = 31$nl$gdb_prompt $" {
     71     pass $t
     72   }
     73 }
     74 
     75 gdb_test "p foo3_1 (0, 1)" \
     76     "Cannot resolve function foo3_1 to any overloaded instance"
     77 gdb_test "p foo3_1 (0, (const char**) 1)" " = 31"
     78 gdb_test "p foo3_2 (0, 0)" "= 32"
     79 gdb_test "p foo3_2 (0, (char const**) 0)" " = 320"
     80 
     81 # Tests for boolean conversions allowed by the standard
     82 gdb_test "p foo1_7(0)" " = 17"
     83 gdb_test "p foo1_7(integer)" " = 17"
     84 gdb_test "p foo1_7(long_int)" " = 17"
     85 gdb_test "p foo1_7(*a)" " = 17"
     86 gdb_test "p foo1_7(MY_A)" " = 17"
     87 gdb_test "p foo1_7(&foo1_7)" " = 17"
     88 gdb_test "p foo1_7(&A::member_)" " = 17"
     89 gdb_test "p foo1_7(a)" " = 17"
     90 gdb_test "p foo1_7(fp)" " = 17"
     91 gdb_test "p foo1_7(dp)" " = 17"
     92 gdb_test "p foo1_7(-1.23)" " = 17"
     93 gdb_test "p foo1_7(ta)" \
     94     "Cannot resolve function foo1_7 to any overloaded instance"
     95 
     96 # Test for strict type checking
     97 set error_str "Cannot resolve function %s to any overloaded instance"
     98 gdb_test "show check type" "Strict type checking is on\." \
     99 	 "confirm check type on"
    100 
    101 with_test_prefix "strict type checking on" {
    102     gdb_test "p foo1_type_check (123)" [format $error_str "foo1_type_check"]
    103     gdb_test "p foo2_type_check (0, 1)" [format $error_str "foo2_type_check"]
    104     gdb_test "p foo2_type_check (1, 0)" [format $error_str "foo2_type_check"]
    105     gdb_test "p foo2_type_check (1, 1)" [format $error_str "foo2_type_check"]
    106     gdb_test "p foo3_type_check (0, 0, 1)" [format $error_str "foo3_type_check"]
    107     gdb_test "p foo3_type_check (0, 1, 0)" [format $error_str "foo3_type_check"]
    108     gdb_test "p foo3_type_check (1, 0, 0)" [format $error_str "foo3_type_check"]
    109     gdb_test "p foo3_type_check (0, 1, 1)" [format $error_str "foo3_type_check"]
    110     gdb_test "p foo3_type_check (1, 1, 0)" [format $error_str "foo3_type_check"]
    111     gdb_test "p foo3_type_check (1, 1, 1)" [format $error_str "foo3_type_check"]
    112 }
    113 
    114 gdb_test_no_output "set check type off"
    115 gdb_test "show check type" "Strict type checking is off\." \
    116 	 "confirm check type off"
    117 
    118 with_test_prefix "strict type checking off" {
    119     gdb_test "p foo1_type_check (123)" " = 1000"
    120     gdb_test "p foo2_type_check (0, 1)" " = 1001"
    121     gdb_test "p foo2_type_check (1, 0)" " = 1001"
    122     gdb_test "p foo2_type_check (1, 1)" " = 1001"
    123     gdb_test "p foo3_type_check (0, 0, 1)" " = 1002"
    124     gdb_test "p foo3_type_check (0, 1, 0)" " = 1002"
    125     gdb_test "p foo3_type_check (1, 0, 0)" " = 1002"
    126     gdb_test "p foo3_type_check (0, 1, 1)" " = 1002"
    127     gdb_test "p foo3_type_check (1, 1, 0)" " = 1002"
    128     gdb_test "p foo3_type_check (1, 1, 1)" " = 1002"
    129     gdb_test "p foo3_2 (1,1)" " = 32"
    130 }
    131