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