From ca6932ad0ccbbbe3c788cd71595d9a25b8ae0d20 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 9 Dec 2019 20:28:39 +0000 Subject: typeck.c (check_for_casting_away_constness): Add location_t parameter and use it. gcc/cp 2019-12-09 Paolo Carlini * typeck.c (check_for_casting_away_constness): Add location_t parameter and use it. (maybe_warn_about_useless_cast): Likewise. (maybe_warn_about_cast_ignoring_quals): Likewise. (build_static_cast_1): Likewise. (build_static_cast): Likewise; sets the location of the returned tree. (build_reinterpret_cast_1): Likewise. (build_reinterpret_cast): Likewise; sets the location of the returned tree. (build_const_cast_1): Likewise. (build_const_cast): Likewise; sets the location of the returned tree. (cp_build_c_cast): Likewise. (build_c_cast): Adjust. (build_ptrmemfunc): Adjust calls. (cp_build_unary_op): Pass the location to invert_truthvalue_loc. * rtti.c (build_dynamic_cast_1): Add location_t parameter and use it. (build_dynamic_cast): Likewise. * cp-tree.h: Adjust declarations. * parser.c (cp_parser_postfix_expression): Pass cp_cast_loc to the various build_*_cast functions. (get_cast_suggestion): Adjust calls. (cp_parser_builtin_offsetof): Likewise. * decl.c (reshape_init): Adjust call. * method.c (forward_parm): Likewise. (build_comparison_op): Likewise. * pt.c (tsubst_copy_and_build): Likewise. * semantics.c (finish_omp_reduction_clause): Likewise. (cp_omp_finish_iterators): Likewise. * tree.c (cp_stabilize_reference): Likewise. (move): Likewise. * typeck2.c (build_functional_cast): Likewise. * typeck2.c (build_functional_cast_1): New. (build_functional_cast_1): Calls the latter and sets the location of the returned tree. /libcc1 2019-12-09 Paolo Carlini * libcp1plugin.cc (plugin_build_cast_expr): Adjust build_cast declaration. gcc/testsuite 2019-12-09 Paolo Carlini * c-c++-common/Wcast-align.c: Check location(s) too. * c-c++-common/Wcast-function-type.c: Likewise. * c-c++-common/Wint-to-pointer-cast-1.c: Likewise. * c-c++-common/Wint-to-pointer-cast-2.c: Likewise. * c-c++-common/Wint-to-pointer-cast-3.c: Likewise. * g++.dg/Wcast-function-type.C: Likewise. * g++.dg/addr_builtin-1.C: Likewise. * g++.dg/conversion/const2.C: Likewise. * g++.dg/conversion/dynamic1.C: Likewise. * g++.dg/conversion/ptrmem2.C: Likewise. * g++.dg/conversion/ptrmem3.C: Likewise. * g++.dg/conversion/qual3.C: Likewise. * g++.dg/conversion/reinterpret3.C: Likewise. * g++.dg/cpp0x/constexpr-cast.C: Likewise. * g++.dg/cpp0x/lambda/lambda-conv11.C: Likewise. * g++.dg/cpp0x/nullptr04.C: Likewise. * g++.dg/cpp0x/reinterpret_cast2.C: Likewise. * g++.dg/cpp0x/rv-cast2.C: Likewise. * g++.dg/cpp1y/lambda-conv1.C: Likewise. * g++.dg/cpp1z/noexcept-type7.C: Likewise. * g++.dg/cpp2a/array-conv9.C: Likewise. * g++.dg/expr/cast11.C: Likewise. * g++.dg/expr/static_cast8.C: Likewise. * g++.dg/ext/vector6.C: Likewise. * g++.dg/other/conversion1.C: Likewise. * g++.dg/parse/pr26997.C: Likewise. * g++.dg/rtti/no-rtti.C: Likewise. * g++.dg/tc1/dr137.C: Likewise. * g++.dg/template/cast4.C: Likewise. * g++.dg/warn/Wcast-qual1.C: Likewise. * g++.dg/warn/Wcast-qual2.C: Likewise. * g++.dg/warn/Wconditionally-supported-1.C: Likewise. * g++.dg/warn/Wuseless-cast.C: Likewise. * g++.dg/warn/pr35711.C: Likewise. * g++.old-deja/g++.bugs/900227_01.C: Likewise. * g++.old-deja/g++.bugs/900404_07.C: Likewise. * g++.old-deja/g++.jason/overload1.C: Likewise. * g++.old-deja/g++.jason/rfg26.C: Likewise. * g++.old-deja/g++.jason/rvalue3.C: Likewise. * g++.old-deja/g++.jason/warning2.C: Likewise. * g++.old-deja/g++.mike/dyncast4.C: Likewise. * g++.old-deja/g++.mike/dyncast6.C: Likewise. * g++.old-deja/g++.mike/p11482.C: Likewise. * g++.old-deja/g++.mike/p2573.C: Likewise. * g++.old-deja/g++.mike/p2855.C: Likewise. * g++.old-deja/g++.mike/p7476.C: Likewise. * g++.old-deja/g++.mike/p8039.C: Likewise. * g++.old-deja/g++.other/cast2.C: Likewise. * g++.old-deja/g++.other/cast3.C: Likewise. * g++.old-deja/g++.other/dcast1.C: Likewise. * g++.old-deja/g++.other/dcast2.C: Likewise. From-SVN: r279138 --- gcc/cp/rtti.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'gcc/cp/rtti.c') diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index da68596..1b6b87b 100644 --- a/gcc/cp/rtti.c +++ b/gcc/cp/rtti.c @@ -123,7 +123,7 @@ static GTY (()) vec *tinfo_descs; static tree ifnonnull (tree, tree, tsubst_flags_t); static tree tinfo_name (tree, bool); -static tree build_dynamic_cast_1 (tree, tree, tsubst_flags_t); +static tree build_dynamic_cast_1 (location_t, tree, tree, tsubst_flags_t); static tree throw_bad_cast (void); static tree throw_bad_typeid (void); static tree get_tinfo_ptr (tree); @@ -548,7 +548,8 @@ ifnonnull (tree test, tree result, tsubst_flags_t complain) paper. */ static tree -build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) +build_dynamic_cast_1 (location_t loc, tree type, tree expr, + tsubst_flags_t complain) { enum tree_code tc = TREE_CODE (type); tree exprtype; @@ -646,7 +647,7 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) tree binfo = lookup_base (TREE_TYPE (exprtype), TREE_TYPE (type), ba_check, NULL, complain); if (binfo) - return build_static_cast (type, expr, complain); + return build_static_cast (loc, type, expr, complain); } /* Apply trivial conversion T -> T& for dereferenced ptrs. */ @@ -691,8 +692,9 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) { tree expr = throw_bad_cast (); if (complain & tf_warning) - warning (0, "%(%#D)%> can never succeed", - type, old_expr); + warning_at (loc, 0, + "%(%#D)%> can never succeed", + type, old_expr); /* Bash it to the expected type. */ TREE_TYPE (expr) = type; return expr; @@ -706,8 +708,9 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) && TREE_CODE (TREE_TYPE (op)) == RECORD_TYPE) { if (complain & tf_warning) - warning (0, "%(%#D)%> can never succeed", - type, op); + warning_at (loc, 0, + "%(%#D)%> can never succeed", + type, op); retval = build_int_cst (type, 0); return retval; } @@ -717,7 +720,8 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) if (!flag_rtti) { if (complain & tf_error) - error ("% not permitted with %<-fno-rtti%>"); + error_at (loc, + "% not permitted with %<-fno-rtti%>"); return error_mark_node; } @@ -796,13 +800,15 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst_flags_t complain) fail: if (complain & tf_error) - error ("cannot % %qE (of type %q#T) to type %q#T (%s)", - old_expr, TREE_TYPE (old_expr), type, errstr); + error_at (loc, "cannot % %qE (of type %q#T) " + "to type %q#T (%s)", + old_expr, TREE_TYPE (old_expr), type, errstr); return error_mark_node; } tree -build_dynamic_cast (tree type, tree expr, tsubst_flags_t complain) +build_dynamic_cast (location_t loc, tree type, tree expr, + tsubst_flags_t complain) { tree r; @@ -813,12 +819,16 @@ build_dynamic_cast (tree type, tree expr, tsubst_flags_t complain) { expr = build_min (DYNAMIC_CAST_EXPR, type, expr); TREE_SIDE_EFFECTS (expr) = 1; - return convert_from_reference (expr); + r = convert_from_reference (expr); + protected_set_expr_location (r, loc); + return r; } - r = convert_from_reference (build_dynamic_cast_1 (type, expr, complain)); + r = convert_from_reference (build_dynamic_cast_1 (loc, type, expr, + complain)); if (r != error_mark_node) - maybe_warn_about_useless_cast (type, expr, complain); + maybe_warn_about_useless_cast (loc, type, expr, complain); + protected_set_expr_location (r, loc); return r; } -- cgit v1.1