old-cross-binutils/gdb/testsuite/gdb.cp/converts.exp
Keith Seitz a451cb65e3 PR c++/13356
* gdbtypes.c (strict_type_checking): New variable.
	(show_strict_type_checking): New function.
	(rank_one_type): Return NS_POINTER_INTEGER_CONVERSION_BADNESS
	if strict type checking is disabled.
	(_initialize_gdbtypes): Add "check type" subcommand.
	* gdbtypes.h (NS_INTEGER_POINTER_CONVERSION_BADNESS): New struct.

	PR c++/13356
	* gdb.base/default.exp: Update all "check type" tests.
	* gdb.base/help.exp: Likewise.
	* gdb.base/setshow.exp: Likewise.
	* gdb.cp/converts.cc (foo1_type_check): New function.
	(foo2_type_check): New function.
	(foo3_type_check): New function.
	(main): Call new functions.
	* converts.exp: Add tests for integer-to-pointer conversions
	with/without strict type-checking.

	PR c++/13356
	* gdb.texinfo (Type and Range Checking): Remove warning.
	Remove spurious commas.
	Update text and examples for re-implementation of set/show
	check type.
	(C and C++ Type and Range Checks): Likewise.

	* language.h (type_mode): Remove.
	(type_check): Remove.
	(struct language_defn): Remove la_type_check.
	(STRICT_TYPE): Remove unused macro.
	(type_error): Remove.
	* language.c (set_type_range_case): Renamed to ...
	(set_range_case): ... this.  Update all callers.
	Remove type_mode/type_check.
	(type_mode): Remove.
	(type_check): Remove.
	(show_type_command): Remove.
	(set_type_command): Remove.
	(language_info): Remove type checking output.
	(type_error): Remove unused function.
	(range_error): Update comment.
	(unknown_language_defn): Remove la_type_check.
	(auto_language_defn): Likewise.
	(local_language_defn): Likewise.
	(_initialize_language): Remove "check type" subcommand.
	* ada-lang.c (ada_language_defn): Remove la_type_check.
	* c-lang.c (c_language_defn): Likewise.
	(cplus_language_defn): Likewise.
	(asm_language_defn): Likewise.
	(minimal_language_defn): Likewise.
	* d-lang.c (d_language_defn): Likewise.
	* f-lang.c (f_language_defn): Likewise.
	* go-lang.c (go_language_defn): Likewise.
	* jv-lang.c (java_language_defn): Likewise.
	* m2-lang.c (m2_language_defn): Likewise.
	* objc-lang.c (objc_language_defn): Likewise.
	* opencl-lang.c (opencl_language_defn): Likewise.
	* p-lang.c (pascal_language_defn): Likewise.
2012-08-17 17:37:03 +00:00

106 lines
4.6 KiB
Text

# Copyright 2008, 2011-2012 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/>.
standard_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
}
gdb_breakpoint [gdb_get_line_number "end of main"]
gdb_continue_to_breakpoint "end of main"
gdb_test "p foo0_1 (ta)" "= 1" "typedef to another typedef"
gdb_test "p foo0_2 (ta)" "= 2" "typedef to typedef of a typedef"
gdb_test "p foo0_3 (bppp)" "Cannot resolve.*" \
"Pointer-to-pointer-to-pointer derived to Pointer-to-pointer-to-pointer base."
gdb_test "p foo1_1 (a)" "= 11" "pointer to pointer"
gdb_test "p foo1_2 (a)" "= 12" "pointer to array"
gdb_test "p foo1_3 (a)" "Cannot resolve.*" "pointer to pointer of wrong type"
gdb_test "p foo1_3 (bp)" "Cannot resolve.*" "pointer to pointer of wrong type"
gdb_test "p foo1_4 (bp)" "= 14" "pointer to ancestor pointer"
gdb_test "p foo1_5 (bp)" "= 15" "pointer to void pointer"
gdb_test "p foo1_6 (bp)" "Cannot resolve.*" "pointer to void pointer pointer"
gdb_test "p foo1_7 (bp)" "= 17" "pointer to boolean"
gdb_test "p foo1_8 (bp)" "Using non-standard.*" "pointer to long int"
gdb_test "p foo1_5 (b)" "= 15" "pointer pointer to void pointer"
gdb_test "p foo2_1 (b)" "= 21" "pointer pointer to pointer pointer"
gdb_test "p foo2_2 (b)" "Cannot resolve.*" "pointer pointer to array of arrays"
gdb_test "p foo2_3 (b)" "= 23" "pointer pointer to array of pointers"
gdb_test "p foo2_4 (b)" "Cannot resolve.*" "pointer pointer to array of wrong pointers"
gdb_test "p foo3_1 ((char *) 0, ta)" "Cannot resolve.*" \
"check all parameters for badness"
# Tests for null pointer conversion
global gdb_prompt
set nl {[\r\n]+}
set t "null pointer conversion"
gdb_test_multiple "p foo3_1 (0, 0)" $t {
-re "warning: Using non-standard conversion.*$nl$gdb_prompt $" {
fail "$t (warning issued)"
}
-re "Cannot resolve function foo3_1 to any overloaded instance$nl$gdb_prompt $" {
fail "$t (conversion failed)"
}
-re "\\$\[0-9\]+ = 31$nl$gdb_prompt $" {
pass $t
}
}
gdb_test "p foo3_1 (0, 1)" \
"Cannot resolve function foo3_1 to any overloaded instance"
gdb_test "p foo3_1 (0, (const char**) 1)" " = 31"
gdb_test "p foo3_2 (0, 0)" "= 32"
gdb_test "p foo3_2 (0, (char const**) 0)" " = 320"
# Test for strict type checking
set error_str "Cannot resolve function %s to any overloaded instance"
gdb_test "show check type" "Strict type checking is on\."
gdb_test "p foo1_type_check (123)" [format $error_str "foo1_type_check"]
gdb_test "p foo2_type_check (0, 1)" [format $error_str "foo2_type_check"]
gdb_test "p foo2_type_check (1, 0)" [format $error_str "foo2_type_check"]
gdb_test "p foo2_type_check (1, 1)" [format $error_str "foo2_type_check"]
gdb_test "p foo3_type_check (0, 0, 1)" [format $error_str "foo3_type_check"]
gdb_test "p foo3_type_check (0, 1, 0)" [format $error_str "foo3_type_check"]
gdb_test "p foo3_type_check (1, 0, 0)" [format $error_str "foo3_type_check"]
gdb_test "p foo3_type_check (0, 1, 1)" [format $error_str "foo3_type_check"]
gdb_test "p foo3_type_check (1, 1, 0)" [format $error_str "foo3_type_check"]
gdb_test "p foo3_type_check (1, 1, 1)" [format $error_str "foo3_type_check"]
gdb_test_no_output "set check type off"
gdb_test "show check type" "Strict type checking is off\."
gdb_test "p foo1_type_check (123)" " = 1000"
gdb_test "p foo2_type_check (0, 1)" " = 1001"
gdb_test "p foo2_type_check (1, 0)" " = 1001"
gdb_test "p foo2_type_check (1, 1)" " = 1001"
gdb_test "p foo3_type_check (0, 0, 1)" " = 1002"
gdb_test "p foo3_type_check (0, 1, 0)" " = 1002"
gdb_test "p foo3_type_check (1, 0, 0)" " = 1002"
gdb_test "p foo3_type_check (0, 1, 1)" " = 1002"
gdb_test "p foo3_type_check (1, 1, 0)" " = 1002"
gdb_test "p foo3_type_check (1, 1, 1)" " = 1002"
gdb_test "p foo3_2 (1,1)" " = 32"