From ca6932ad0ccbbbe3c788cd71595d9a25b8ae0d20 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 9 Dec 2019 20:28:39 +0000 Subject: [PATCH] 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/ChangeLog | 39 +++ gcc/cp/cp-tree.h | 18 +- gcc/cp/decl.c | 3 +- gcc/cp/method.c | 9 +- gcc/cp/parser.c | 38 +-- gcc/cp/pt.c | 8 +- gcc/cp/rtti.c | 38 +-- gcc/cp/semantics.c | 21 +- gcc/cp/tree.c | 6 +- gcc/cp/typeck.c | 238 ++++++++++-------- gcc/cp/typeck2.c | 19 +- gcc/testsuite/ChangeLog | 54 ++++ gcc/testsuite/c-c++-common/Wcast-align.c | 4 +- .../c-c++-common/Wcast-function-type.c | 4 +- .../c-c++-common/Wint-to-pointer-cast-1.c | 2 +- .../c-c++-common/Wint-to-pointer-cast-2.c | 2 +- .../c-c++-common/Wint-to-pointer-cast-3.c | 4 +- gcc/testsuite/g++.dg/Wcast-function-type.C | 2 +- gcc/testsuite/g++.dg/addr_builtin-1.C | 4 +- gcc/testsuite/g++.dg/conversion/const2.C | 2 +- gcc/testsuite/g++.dg/conversion/dynamic1.C | 2 +- gcc/testsuite/g++.dg/conversion/ptrmem2.C | 8 +- gcc/testsuite/g++.dg/conversion/ptrmem3.C | 4 +- gcc/testsuite/g++.dg/conversion/qual3.C | 26 +- .../g++.dg/conversion/reinterpret3.C | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C | 6 +- .../g++.dg/cpp0x/lambda/lambda-conv11.C | 6 +- gcc/testsuite/g++.dg/cpp0x/nullptr04.C | 8 +- .../g++.dg/cpp0x/reinterpret_cast2.C | 2 +- gcc/testsuite/g++.dg/cpp0x/rv-cast2.C | 6 +- gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C | 12 +- gcc/testsuite/g++.dg/cpp1z/noexcept-type7.C | 2 +- gcc/testsuite/g++.dg/cpp2a/array-conv9.C | 4 +- gcc/testsuite/g++.dg/expr/cast11.C | 24 +- gcc/testsuite/g++.dg/expr/static_cast8.C | 12 +- gcc/testsuite/g++.dg/ext/vector6.C | 2 +- gcc/testsuite/g++.dg/other/conversion1.C | 2 +- gcc/testsuite/g++.dg/parse/pr26997.C | 8 +- gcc/testsuite/g++.dg/rtti/no-rtti.C | 2 +- gcc/testsuite/g++.dg/tc1/dr137.C | 2 +- gcc/testsuite/g++.dg/template/cast4.C | 2 +- gcc/testsuite/g++.dg/warn/Wcast-qual1.C | 2 +- gcc/testsuite/g++.dg/warn/Wcast-qual2.C | 2 +- .../g++.dg/warn/Wconditionally-supported-1.C | 8 +- gcc/testsuite/g++.dg/warn/Wuseless-cast.C | 64 ++--- gcc/testsuite/g++.dg/warn/pr35711.C | 2 +- .../g++.old-deja/g++.bugs/900227_01.C | 4 +- .../g++.old-deja/g++.bugs/900404_07.C | 2 +- .../g++.old-deja/g++.jason/overload1.C | 2 +- gcc/testsuite/g++.old-deja/g++.jason/rfg26.C | 2 +- .../g++.old-deja/g++.jason/rvalue3.C | 2 +- .../g++.old-deja/g++.jason/warning2.C | 2 +- .../g++.old-deja/g++.mike/dyncast4.C | 2 +- .../g++.old-deja/g++.mike/dyncast6.C | 2 +- gcc/testsuite/g++.old-deja/g++.mike/p11482.C | 2 +- gcc/testsuite/g++.old-deja/g++.mike/p2573.C | 6 +- gcc/testsuite/g++.old-deja/g++.mike/p2855.C | 2 +- gcc/testsuite/g++.old-deja/g++.mike/p7476.C | 2 +- gcc/testsuite/g++.old-deja/g++.mike/p8039.C | 2 +- gcc/testsuite/g++.old-deja/g++.other/cast2.C | 9 +- gcc/testsuite/g++.old-deja/g++.other/cast3.C | 12 +- gcc/testsuite/g++.old-deja/g++.other/dcast1.C | 4 +- gcc/testsuite/g++.old-deja/g++.other/dcast2.C | 2 +- libcc1/ChangeLog | 5 + libcc1/libcp1plugin.cc | 5 +- 65 files changed, 484 insertions(+), 320 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a3fe71e222d..b39a304b17d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,42 @@ +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. + 2019-12-08 Jakub Jelinek * cvt.c (maybe_warn_nodiscard): Add workaround for GCC 3.4-4.4 - cast diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index d7df6d91dae..b47698e1d0c 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7000,7 +7000,8 @@ extern tree build_typeid (tree, tsubst_flags_t); extern tree get_tinfo_decl (tree); extern tree get_typeid (tree, tsubst_flags_t); extern tree build_headof (tree); -extern tree build_dynamic_cast (tree, tree, tsubst_flags_t); +extern tree build_dynamic_cast (location_t, tree, tree, + tsubst_flags_t); extern void emit_support_tinfos (void); extern bool emit_tinfo_decl (tree); @@ -7549,13 +7550,17 @@ extern tree build_x_compound_expr (location_t, tree, tree, tsubst_flags_t); extern tree build_compound_expr (location_t, tree, tree); extern tree cp_build_compound_expr (tree, tree, tsubst_flags_t); -extern tree build_static_cast (tree, tree, tsubst_flags_t); -extern tree build_reinterpret_cast (tree, tree, tsubst_flags_t); -extern tree build_const_cast (tree, tree, tsubst_flags_t); +extern tree build_static_cast (location_t, tree, tree, + tsubst_flags_t); +extern tree build_reinterpret_cast (location_t, tree, tree, + tsubst_flags_t); +extern tree build_const_cast (location_t, tree, tree, + tsubst_flags_t); extern tree build_c_cast (location_t, tree, tree); extern cp_expr build_c_cast (location_t loc, tree type, cp_expr expr); -extern tree cp_build_c_cast (tree, tree, tsubst_flags_t); +extern tree cp_build_c_cast (location_t, tree, tree, + tsubst_flags_t); extern cp_expr build_x_modify_expr (location_t, tree, enum tree_code, tree, tsubst_flags_t); @@ -7615,7 +7620,8 @@ extern int lvalue_or_else (tree, enum lvalue_use, extern void check_template_keyword (tree); extern bool check_raw_literal_operator (const_tree decl); extern bool check_literal_operator_args (const_tree, bool *, bool *); -extern void maybe_warn_about_useless_cast (tree, tree, tsubst_flags_t); +extern void maybe_warn_about_useless_cast (location_t, tree, tree, + tsubst_flags_t); extern tree cp_perform_integral_promotions (tree, tsubst_flags_t); extern tree finish_left_unary_fold_expr (tree, int); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index b5d689ad03b..6dec5838303 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6490,7 +6490,8 @@ reshape_init (tree type, tree init, tsubst_flags_t complain) { warning_sentinel w (warn_useless_cast); warning_sentinel w2 (warn_ignored_qualifiers); - return cp_build_c_cast (type, elt, tf_warning_or_error); + return cp_build_c_cast (input_location, type, elt, + tf_warning_or_error); } else return error_mark_node; diff --git a/gcc/cp/method.c b/gcc/cp/method.c index d2aed473d77..83da20a0779 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -474,7 +474,8 @@ forward_parm (tree parm) if (!TYPE_REF_P (type)) type = cp_build_reference_type (type, /*rval=*/true); warning_sentinel w (warn_useless_cast); - exp = build_static_cast (type, exp, tf_warning_or_error); + exp = build_static_cast (input_location, type, exp, + tf_warning_or_error); if (DECL_PACK_P (parm)) exp = make_pack_expansion (exp); return exp; @@ -1361,7 +1362,8 @@ build_comparison_op (tree fndecl, tsubst_flags_t complain) if (TREE_CODE (comp) == SPACESHIP_EXPR) TREE_TYPE (comp) = rettype; else - comp = build_static_cast (rettype, comp, complain); + comp = build_static_cast (input_location, rettype, comp, + complain); info.check (comp); if (info.defining) { @@ -1395,7 +1397,8 @@ build_comparison_op (tree fndecl, tsubst_flags_t complain) { tree seql = lookup_comparison_result (cc_strong_ordering, "equal", complain); - val = build_static_cast (rettype, seql, complain); + val = build_static_cast (input_location, rettype, seql, + complain); } finish_return_stmt (val); } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 1ea19ce824a..bf6d291ba9d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -6896,36 +6896,38 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, break; } + /* Construct a location e.g. : + reinterpret_cast (expr) + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ranging from the start of the "*_cast" token to the final closing + paren, with the caret at the start. */ + location_t cp_cast_loc = make_location (start_loc, start_loc, end_loc); + switch (keyword) { case RID_DYNCAST: postfix_expression - = build_dynamic_cast (type, expression, tf_warning_or_error); + = build_dynamic_cast (cp_cast_loc, type, expression, + tf_warning_or_error); break; case RID_STATCAST: postfix_expression - = build_static_cast (type, expression, tf_warning_or_error); + = build_static_cast (cp_cast_loc, type, expression, + tf_warning_or_error); break; case RID_REINTCAST: postfix_expression - = build_reinterpret_cast (type, expression, + = build_reinterpret_cast (cp_cast_loc, type, expression, tf_warning_or_error); break; case RID_CONSTCAST: postfix_expression - = build_const_cast (type, expression, tf_warning_or_error); + = build_const_cast (cp_cast_loc, type, expression, + tf_warning_or_error); break; default: gcc_unreachable (); } - - /* Construct a location e.g. : - reinterpret_cast (expr) - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ranging from the start of the "*_cast" token to the final closing - paren, with the caret at the start. */ - location_t cp_cast_loc = make_location (start_loc, start_loc, end_loc); - postfix_expression.set_location (cp_cast_loc); } break; @@ -9151,17 +9153,18 @@ get_cast_suggestion (tree dst_type, tree orig_expr) return NULL; /* First try const_cast. */ - trial = build_const_cast (dst_type, orig_expr, tf_none); + trial = build_const_cast (input_location, dst_type, orig_expr, tf_none); if (trial != error_mark_node) return "const_cast"; /* If that fails, try static_cast. */ - trial = build_static_cast (dst_type, orig_expr, tf_none); + trial = build_static_cast (input_location, dst_type, orig_expr, tf_none); if (trial != error_mark_node) return "static_cast"; /* Finally, try reinterpret_cast. */ - trial = build_reinterpret_cast (dst_type, orig_expr, tf_none); + trial = build_reinterpret_cast (input_location, dst_type, orig_expr, + tf_none); if (trial != error_mark_node) return "reinterpret_cast"; @@ -10149,8 +10152,8 @@ cp_parser_builtin_offsetof (cp_parser *parser) /* Build the (type *)null that begins the traditional offsetof macro. */ tree object_ptr - = build_static_cast (build_pointer_type (type), null_pointer_node, - tf_warning_or_error); + = build_static_cast (input_location, build_pointer_type (type), + null_pointer_node, tf_warning_or_error); /* Parse the offsetof-member-designator. We begin as if we saw "expr->". */ expr = cp_parser_postfix_dot_deref_expression (parser, CPP_DEREF, object_ptr, @@ -29278,7 +29281,6 @@ cp_parser_functional_cast (cp_parser* parser, tree type) parser->lexer); cast = build_functional_cast (combined_loc, type, expression_list, tf_warning_or_error); - cast.set_location (combined_loc); /* [expr.const]/1: In an integral constant expression "only type conversions to integral or enumeration type can be used". */ diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index d845a886b92..d8ab26ec675 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -19024,16 +19024,16 @@ tsubst_copy_and_build (tree t, r = build_functional_cast (input_location, type, op, complain); break; case REINTERPRET_CAST_EXPR: - r = build_reinterpret_cast (type, op, complain); + r = build_reinterpret_cast (input_location, type, op, complain); break; case CONST_CAST_EXPR: - r = build_const_cast (type, op, complain); + r = build_const_cast (input_location, type, op, complain); break; case DYNAMIC_CAST_EXPR: - r = build_dynamic_cast (type, op, complain); + r = build_dynamic_cast (input_location, type, op, complain); break; case STATIC_CAST_EXPR: - r = build_static_cast (type, op, complain); + r = build_static_cast (input_location, type, op, complain); break; default: gcc_unreachable (); diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index da685961c70..1b6b87ba8d6 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; } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 83a7891e57b..42611682549 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5918,9 +5918,11 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) if (need_static_cast) { tree rtype = build_reference_type (atype); - omp_out = build_static_cast (rtype, omp_out, + omp_out = build_static_cast (input_location, + rtype, omp_out, tf_warning_or_error); - omp_in = build_static_cast (rtype, omp_in, + omp_in = build_static_cast (input_location, + rtype, omp_in, tf_warning_or_error); if (omp_out == error_mark_node || omp_in == error_mark_node) return true; @@ -5955,9 +5957,11 @@ finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor) return true; } tree rtype = build_reference_type (atype); - omp_priv = build_static_cast (rtype, omp_priv, + omp_priv = build_static_cast (input_location, + rtype, omp_priv, tf_warning_or_error); - omp_orig = build_static_cast (rtype, omp_orig, + omp_orig = build_static_cast (input_location, + rtype, omp_orig, tf_warning_or_error); if (omp_priv == error_mark_node || omp_orig == error_mark_node) @@ -6138,13 +6142,16 @@ cp_omp_finish_iterators (tree iter) begin = mark_rvalue_use (begin); end = mark_rvalue_use (end); step = mark_rvalue_use (step); - begin = cp_build_c_cast (type, begin, tf_warning_or_error); - end = cp_build_c_cast (type, end, tf_warning_or_error); + begin = cp_build_c_cast (input_location, type, begin, + tf_warning_or_error); + end = cp_build_c_cast (input_location, type, end, + tf_warning_or_error); orig_step = step; if (!processing_template_decl) step = orig_step = save_expr (step); tree stype = POINTER_TYPE_P (type) ? sizetype : type; - step = cp_build_c_cast (stype, step, tf_warning_or_error); + step = cp_build_c_cast (input_location, stype, step, + tf_warning_or_error); if (POINTER_TYPE_P (type) && !processing_template_decl) { begin = save_expr (begin); diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 57745543163..c7c063f6df7 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -425,7 +425,8 @@ cp_stabilize_reference (tree ref) /* This inhibits warnings in, eg, cxx_mark_addressable (c++/60955). */ warning_sentinel s (extra_warnings); - ref = build_static_cast (type, ref, tf_error); + ref = build_static_cast (input_location, type, ref, + tf_error); } } @@ -1222,7 +1223,8 @@ move (tree expr) tree type = TREE_TYPE (expr); gcc_assert (!TYPE_REF_P (type)); type = cp_build_reference_type (type, /*rval*/true); - return build_static_cast (type, expr, tf_warning_or_error); + return build_static_cast (input_location, type, expr, + tf_warning_or_error); } /* Used by the C++ front end to build qualified array types. However, diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index bf59550663b..d0f739895c9 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6460,7 +6460,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, bool noconvert, build_zero_cst (TREE_TYPE (arg)), complain); arg = perform_implicit_conversion (boolean_type_node, arg, complain); - val = invert_truthvalue_loc (input_location, arg); + val = invert_truthvalue_loc (location, arg); if (arg != error_mark_node) return val; errstring = _("in argument to unary !"); @@ -7093,8 +7093,9 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain) */ static bool -check_for_casting_away_constness (tree src_type, tree dest_type, - enum tree_code cast, tsubst_flags_t complain) +check_for_casting_away_constness (location_t loc, tree src_type, + tree dest_type, enum tree_code cast, + tsubst_flags_t complain) { /* C-style casts are allowed to cast away constness. With WARN_CAST_QUAL, we still want to issue a warning. */ @@ -7108,23 +7109,23 @@ check_for_casting_away_constness (tree src_type, tree dest_type, { case CAST_EXPR: if (complain & tf_warning) - warning (OPT_Wcast_qual, - "cast from type %qT to type %qT casts away qualifiers", - src_type, dest_type); + warning_at (loc, OPT_Wcast_qual, + "cast from type %qT to type %qT casts away qualifiers", + src_type, dest_type); return false; - + case STATIC_CAST_EXPR: if (complain & tf_error) - error ("% from type %qT to type %qT casts away " - "qualifiers", - src_type, dest_type); + error_at (loc, "% from type %qT to type %qT casts " + "away qualifiers", + src_type, dest_type); return true; - + case REINTERPRET_CAST_EXPR: if (complain & tf_error) - error ("% from type %qT to type %qT casts away " - "qualifiers", - src_type, dest_type); + error_at (loc, "% from type %qT to type %qT " + "casts away qualifiers", + src_type, dest_type); return true; default: @@ -7134,7 +7135,8 @@ check_for_casting_away_constness (tree src_type, tree dest_type, /* Warns if the cast from expression EXPR to type TYPE is useless. */ void -maybe_warn_about_useless_cast (tree type, tree expr, tsubst_flags_t complain) +maybe_warn_about_useless_cast (location_t loc, tree type, tree expr, + tsubst_flags_t complain) { if (warn_useless_cast && complain & tf_warning) @@ -7144,22 +7146,22 @@ maybe_warn_about_useless_cast (tree type, tree expr, tsubst_flags_t complain) ? xvalue_p (expr) : lvalue_p (expr)) && same_type_p (TREE_TYPE (expr), TREE_TYPE (type))) || same_type_p (TREE_TYPE (expr), type)) - warning (OPT_Wuseless_cast, "useless cast to type %q#T", type); + warning_at (loc, OPT_Wuseless_cast, + "useless cast to type %q#T", type); } } /* Warns if the cast ignores cv-qualifiers on TYPE. */ -void -maybe_warn_about_cast_ignoring_quals (tree type, tsubst_flags_t complain) +static void +maybe_warn_about_cast_ignoring_quals (location_t loc, tree type, + tsubst_flags_t complain) { if (warn_ignored_qualifiers && complain & tf_warning && !CLASS_TYPE_P (type) && (cp_type_quals (type) & (TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE))) - { - warning (OPT_Wignored_qualifiers, "type qualifiers ignored on cast " - "result type"); - } + warning_at (loc, OPT_Wignored_qualifiers, + "type qualifiers ignored on cast result type"); } /* Convert EXPR (an expression with pointer-to-member type) to TYPE @@ -7218,7 +7220,7 @@ convert_ptrmem (tree type, tree expr, bool allow_inverse_p, indicate whether or not the cast was valid. */ static tree -build_static_cast_1 (tree type, tree expr, bool c_cast_p, +build_static_cast_1 (location_t loc, tree type, tree expr, bool c_cast_p, bool *valid_p, tsubst_flags_t complain) { tree intype; @@ -7287,7 +7289,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, if (sanitize_flags_p (SANITIZE_VPTR)) { tree ubsan_check - = cp_ubsan_maybe_instrument_downcast (input_location, type, + = cp_ubsan_maybe_instrument_downcast (loc, type, intype, expr); if (ubsan_check) expr = ubsan_check; @@ -7445,7 +7447,8 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, return expr; if (!c_cast_p - && check_for_casting_away_constness (intype, type, STATIC_CAST_EXPR, + && check_for_casting_away_constness (loc, intype, type, + STATIC_CAST_EXPR, complain)) return error_mark_node; base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype), @@ -7457,7 +7460,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, if (sanitize_flags_p (SANITIZE_VPTR)) { tree ubsan_check - = cp_ubsan_maybe_instrument_downcast (input_location, type, + = cp_ubsan_maybe_instrument_downcast (loc, type, intype, expr); if (ubsan_check) expr = ubsan_check; @@ -7494,7 +7497,7 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, if (can_convert (t1, t2, complain) || can_convert (t2, t1, complain)) { if (!c_cast_p - && check_for_casting_away_constness (intype, type, + && check_for_casting_away_constness (loc, intype, type, STATIC_CAST_EXPR, complain)) return error_mark_node; @@ -7516,7 +7519,8 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, && TYPE_PTROB_P (type)) { if (!c_cast_p - && check_for_casting_away_constness (intype, type, STATIC_CAST_EXPR, + && check_for_casting_away_constness (loc, intype, type, + STATIC_CAST_EXPR, complain)) return error_mark_node; if (processing_template_decl) @@ -7531,7 +7535,8 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p, /* Return an expression representing static_cast(EXPR). */ tree -build_static_cast (tree type, tree oexpr, tsubst_flags_t complain) +build_static_cast (location_t loc, tree type, tree oexpr, + tsubst_flags_t complain) { tree expr = oexpr; tree result; @@ -7548,7 +7553,9 @@ build_static_cast (tree type, tree oexpr, tsubst_flags_t complain) expr = build_min (STATIC_CAST_EXPR, type, oexpr); /* We don't know if it will or will not have side effects. */ TREE_SIDE_EFFECTS (expr) = 1; - return convert_from_reference (expr); + result = convert_from_reference (expr); + protected_set_expr_location (result, loc); + return result; } else if (processing_template_decl) expr = build_non_dependent_expr (expr); @@ -7560,24 +7567,25 @@ build_static_cast (tree type, tree oexpr, tsubst_flags_t complain) && TREE_TYPE (expr) == TREE_TYPE (TREE_OPERAND (expr, 0))) expr = TREE_OPERAND (expr, 0); - result = build_static_cast_1 (type, expr, /*c_cast_p=*/false, &valid_p, - complain); + result = build_static_cast_1 (loc, type, expr, /*c_cast_p=*/false, + &valid_p, complain); if (valid_p) { if (result != error_mark_node) { - maybe_warn_about_useless_cast (type, expr, complain); - maybe_warn_about_cast_ignoring_quals (type, complain); + maybe_warn_about_useless_cast (loc, type, expr, complain); + maybe_warn_about_cast_ignoring_quals (loc, type, complain); } if (processing_template_decl) goto tmpl; + protected_set_expr_location (result, loc); return result; } if (complain & tf_error) { - error ("invalid % from type %qT to type %qT", - TREE_TYPE (expr), type); + error_at (loc, "invalid % from type %qT to type %qT", + TREE_TYPE (expr), type); if ((TYPE_PTR_P (type) || TYPE_REF_P (type)) && CLASS_TYPE_P (TREE_TYPE (type)) && !COMPLETE_TYPE_P (TREE_TYPE (type))) @@ -7651,8 +7659,9 @@ build_nop_reinterpret (tree type, tree expr) indicate whether or not reinterpret_cast was valid. */ static tree -build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, - bool *valid_p, tsubst_flags_t complain) +build_reinterpret_cast_1 (location_t loc, tree type, tree expr, + bool c_cast_p, bool *valid_p, + tsubst_flags_t complain) { tree intype; @@ -7688,9 +7697,9 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, else if (!lvalue_p (expr)) { if (complain & tf_error) - error ("invalid cast of an rvalue expression of type " - "%qT to type %qT", - intype, type); + error_at (loc, "invalid cast of an rvalue expression of type " + "%qT to type %qT", + intype, type); return error_mark_node; } @@ -7701,8 +7710,8 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, && (complain & tf_warning) && (comptypes (TREE_TYPE (intype), TREE_TYPE (type), COMPARE_BASE | COMPARE_DERIVED))) - warning (0, "casting %qT to %qT does not dereference pointer", - intype, type); + warning_at (loc, 0, "casting %qT to %qT does not dereference pointer", + intype, type); expr = cp_build_addr_expr (expr, complain); @@ -7711,7 +7720,7 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, if (expr != error_mark_node) expr = build_reinterpret_cast_1 - (build_pointer_type (TREE_TYPE (type)), expr, c_cast_p, + (loc, build_pointer_type (TREE_TYPE (type)), expr, c_cast_p, valid_p, complain); if (expr != error_mark_node) /* cp_build_indirect_ref isn't right for rvalue refs. */ @@ -7758,7 +7767,7 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, if (TYPE_PRECISION (type) < TYPE_PRECISION (intype)) { if (complain & tf_error) - permerror (input_location, "cast from %qH to %qI loses precision", + permerror (loc, "cast from %qH to %qI loses precision", intype, type); else return error_mark_node; @@ -7782,9 +7791,9 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, if ((complain & tf_warning) && !cxx_safe_function_type_cast_p (TREE_TYPE (type), TREE_TYPE (intype))) - warning (OPT_Wcast_function_type, - "cast between incompatible function types" - " from %qH to %qI", intype, type); + warning_at (loc, OPT_Wcast_function_type, + "cast between incompatible function types" + " from %qH to %qI", intype, type); return build_nop_reinterpret (type, expr); } else if (TYPE_PTRMEMFUNC_P (type) && TYPE_PTRMEMFUNC_P (intype)) @@ -7793,16 +7802,16 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, && !cxx_safe_function_type_cast_p (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (type)), TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE_RAW (intype)))) - warning (OPT_Wcast_function_type, - "cast between incompatible pointer to member types" - " from %qH to %qI", intype, type); + warning_at (loc, OPT_Wcast_function_type, + "cast between incompatible pointer to member types" + " from %qH to %qI", intype, type); return build_nop_reinterpret (type, expr); } else if ((TYPE_PTRDATAMEM_P (type) && TYPE_PTRDATAMEM_P (intype)) || (TYPE_PTROBV_P (type) && TYPE_PTROBV_P (intype))) { if (!c_cast_p - && check_for_casting_away_constness (intype, type, + && check_for_casting_away_constness (loc, intype, type, REINTERPRET_CAST_EXPR, complain)) return error_mark_node; @@ -7815,8 +7824,9 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, && COMPLETE_TYPE_P (TREE_TYPE (intype)) && min_align_of_type (TREE_TYPE (type)) > min_align_of_type (TREE_TYPE (intype))) - warning (OPT_Wcast_align, "cast from %qH to %qI " - "increases required alignment of target type", intype, type); + warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI " + "increases required alignment of target type", + intype, type); if (warn_strict_aliasing <= 2) /* strict_aliasing_warning STRIP_NOPs its expr. */ @@ -7830,9 +7840,9 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, if (complain & tf_warning) /* C++11 5.2.10 p8 says that "Converting a function pointer to an object pointer type or vice versa is conditionally-supported." */ - warning (OPT_Wconditionally_supported, - "casting between pointer-to-function and pointer-to-object " - "is conditionally-supported"); + warning_at (loc, OPT_Wconditionally_supported, + "casting between pointer-to-function and " + "pointer-to-object is conditionally-supported"); return build_nop_reinterpret (type, expr); } else if (gnu_vector_type_p (type)) @@ -7845,7 +7855,8 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, if (valid_p) *valid_p = false; if (complain & tf_error) - error ("invalid cast from type %qT to type %qT", intype, type); + error_at (loc, "invalid cast from type %qT to type %qT", + intype, type); return error_mark_node; } @@ -7857,7 +7868,8 @@ build_reinterpret_cast_1 (tree type, tree expr, bool c_cast_p, } tree -build_reinterpret_cast (tree type, tree expr, tsubst_flags_t complain) +build_reinterpret_cast (location_t loc, tree type, tree expr, + tsubst_flags_t complain) { tree r; @@ -7872,16 +7884,19 @@ build_reinterpret_cast (tree type, tree expr, tsubst_flags_t complain) && type_dependent_expression_p (expr)) /* There might turn out to be side effects inside expr. */ TREE_SIDE_EFFECTS (t) = 1; - return convert_from_reference (t); + r = convert_from_reference (t); + protected_set_expr_location (r, loc); + return r; } - r = build_reinterpret_cast_1 (type, expr, /*c_cast_p=*/false, + r = build_reinterpret_cast_1 (loc, type, expr, /*c_cast_p=*/false, /*valid_p=*/NULL, complain); if (r != error_mark_node) { - maybe_warn_about_useless_cast (type, expr, complain); - maybe_warn_about_cast_ignoring_quals (type, complain); + maybe_warn_about_useless_cast (loc, type, expr, complain); + maybe_warn_about_cast_ignoring_quals (loc, type, complain); } + protected_set_expr_location (r, loc); return r; } @@ -7893,8 +7908,8 @@ build_reinterpret_cast (tree type, tree expr, tsubst_flags_t complain) whether or not the conversion succeeded. */ static tree -build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, - bool *valid_p) +build_const_cast_1 (location_t loc, tree dst_type, tree expr, + tsubst_flags_t complain, bool *valid_p) { tree src_type; tree reference_type; @@ -7913,19 +7928,19 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, if (!INDIRECT_TYPE_P (dst_type) && !TYPE_PTRDATAMEM_P (dst_type)) { if (complain & tf_error) - error ("invalid use of % with type %qT, " - "which is not a pointer, " - "reference, nor a pointer-to-data-member type", dst_type); + error_at (loc, "invalid use of % with type %qT, " + "which is not a pointer, reference, " + "nor a pointer-to-data-member type", dst_type); return error_mark_node; } if (TREE_CODE (TREE_TYPE (dst_type)) == FUNCTION_TYPE) { if (complain & tf_error) - error ("invalid use of % with type %qT, " - "which is a pointer or reference to a function type", - dst_type); - return error_mark_node; + error_at (loc, "invalid use of % with type %qT, " + "which is a pointer or reference to a function type", + dst_type); + return error_mark_node; } /* A prvalue of non-class type is cv-unqualified. */ @@ -7964,10 +7979,10 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, else { if (complain & tf_error) - error ("invalid % of an rvalue of type %qT " - "to type %qT", - src_type, dst_type); - return error_mark_node; + error_at (loc, "invalid % of an rvalue of type %qT " + "to type %qT", + src_type, dst_type); + return error_mark_node; } dst_type = build_pointer_type (TREE_TYPE (dst_type)); src_type = build_pointer_type (src_type); @@ -7992,16 +8007,16 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, *valid_p = true; /* This cast is actually a C-style cast. Issue a warning if the user is making a potentially unsafe cast. */ - check_for_casting_away_constness (src_type, dst_type, + check_for_casting_away_constness (loc, src_type, dst_type, CAST_EXPR, complain); /* ??? comp_ptr_ttypes_const ignores TYPE_ALIGN. */ if ((STRICT_ALIGNMENT || warn_cast_align == 2) && (complain & tf_warning) && min_align_of_type (TREE_TYPE (dst_type)) > min_align_of_type (TREE_TYPE (src_type))) - warning (OPT_Wcast_align, "cast from %qH to %qI " - "increases required alignment of target type", - src_type, dst_type); + warning_at (loc, OPT_Wcast_align, "cast from %qH to %qI " + "increases required alignment of target type", + src_type, dst_type); } if (reference_type) { @@ -8029,18 +8044,19 @@ build_const_cast_1 (tree dst_type, tree expr, tsubst_flags_t complain, else if (valid_p && !at_least_as_qualified_p (TREE_TYPE (dst_type), TREE_TYPE (src_type))) - check_for_casting_away_constness (src_type, dst_type, CAST_EXPR, - complain); + check_for_casting_away_constness (loc, src_type, dst_type, + CAST_EXPR, complain); } if (complain & tf_error) - error ("invalid % from type %qT to type %qT", - src_type, dst_type); + error_at (loc, "invalid % from type %qT to type %qT", + src_type, dst_type); return error_mark_node; } tree -build_const_cast (tree type, tree expr, tsubst_flags_t complain) +build_const_cast (location_t loc, tree type, tree expr, + tsubst_flags_t complain) { tree r; @@ -8055,24 +8071,27 @@ build_const_cast (tree type, tree expr, tsubst_flags_t complain) && type_dependent_expression_p (expr)) /* There might turn out to be side effects inside expr. */ TREE_SIDE_EFFECTS (t) = 1; - return convert_from_reference (t); + r = convert_from_reference (t); + protected_set_expr_location (r, loc); + return r; } - r = build_const_cast_1 (type, expr, complain, /*valid_p=*/NULL); + r = build_const_cast_1 (loc, type, expr, complain, /*valid_p=*/NULL); if (r != error_mark_node) { - maybe_warn_about_useless_cast (type, expr, complain); - maybe_warn_about_cast_ignoring_quals (type, complain); + maybe_warn_about_useless_cast (loc, type, expr, complain); + maybe_warn_about_cast_ignoring_quals (loc, type, complain); } + protected_set_expr_location (r, loc); return r; } /* Like cp_build_c_cast, but for the c-common bits. */ tree -build_c_cast (location_t /*loc*/, tree type, tree expr) +build_c_cast (location_t loc, tree type, tree expr) { - return cp_build_c_cast (type, expr, tf_warning_or_error); + return cp_build_c_cast (loc, type, expr, tf_warning_or_error); } /* Like the "build_c_cast" used for c-common, but using cp_expr to @@ -8082,7 +8101,7 @@ build_c_cast (location_t /*loc*/, tree type, tree expr) cp_expr build_c_cast (location_t loc, tree type, cp_expr expr) { - cp_expr result = cp_build_c_cast (type, expr, tf_warning_or_error); + cp_expr result = cp_build_c_cast (loc, type, expr, tf_warning_or_error); result.set_location (loc); return result; } @@ -8091,7 +8110,8 @@ build_c_cast (location_t loc, tree type, cp_expr expr) TYPE of expression EXPR. */ tree -cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) +cp_build_c_cast (location_t loc, tree type, tree expr, + tsubst_flags_t complain) { tree value = expr; tree result; @@ -8130,7 +8150,8 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) if (TYPE_PTR_P (TREE_TYPE (expr))) { if (complain & tf_error) - permerror (input_location, "ISO C++ forbids casting to an array type %qT", type); + permerror (loc, "ISO C++ forbids casting to an array type %qT", + type); else return error_mark_node; type = build_pointer_type (TREE_TYPE (type)); @@ -8138,7 +8159,8 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) else { if (complain & tf_error) - error ("ISO C++ forbids casting to an array type %qT", type); + error_at (loc, "ISO C++ forbids casting to an array type %qT", + type); return error_mark_node; } } @@ -8146,7 +8168,7 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) if (FUNC_OR_METHOD_TYPE_P (type)) { if (complain & tf_error) - error ("invalid cast to function type %qT", type); + error_at (loc, "invalid cast to function type %qT", type); return error_mark_node; } @@ -8156,28 +8178,28 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) && TYPE_PRECISION (type) > TYPE_PRECISION (TREE_TYPE (value)) /* Don't warn about converting any constant. */ && !TREE_CONSTANT (value)) - warning_at (input_location, OPT_Wint_to_pointer_cast, + warning_at (loc, OPT_Wint_to_pointer_cast, "cast to pointer from integer of different size"); /* A C-style cast can be a const_cast. */ - result = build_const_cast_1 (type, value, complain & tf_warning, + result = build_const_cast_1 (loc, type, value, complain & tf_warning, &valid_p); if (valid_p) { if (result != error_mark_node) { - maybe_warn_about_useless_cast (type, value, complain); - maybe_warn_about_cast_ignoring_quals (type, complain); + maybe_warn_about_useless_cast (loc, type, value, complain); + maybe_warn_about_cast_ignoring_quals (loc, type, complain); } return result; } /* Or a static cast. */ - result = build_static_cast_1 (type, value, /*c_cast_p=*/true, + result = build_static_cast_1 (loc, type, value, /*c_cast_p=*/true, &valid_p, complain); /* Or a reinterpret_cast. */ if (!valid_p) - result = build_reinterpret_cast_1 (type, value, /*c_cast_p=*/true, + result = build_reinterpret_cast_1 (loc, type, value, /*c_cast_p=*/true, &valid_p, complain); /* The static_cast or reinterpret_cast may be followed by a const_cast. */ @@ -8188,8 +8210,8 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) { tree result_type; - maybe_warn_about_useless_cast (type, value, complain); - maybe_warn_about_cast_ignoring_quals (type, complain); + maybe_warn_about_useless_cast (loc, type, value, complain); + maybe_warn_about_cast_ignoring_quals (loc, type, complain); /* Non-class rvalues always have cv-unqualified type. */ if (!CLASS_TYPE_P (type)) @@ -8204,7 +8226,7 @@ cp_build_c_cast (tree type, tree expr, tsubst_flags_t complain) to succeed. */ if (!same_type_p (non_reference (type), non_reference (result_type))) { - result = build_const_cast_1 (type, result, false, &valid_p); + result = build_const_cast_1 (loc, type, result, false, &valid_p); gcc_assert (valid_p); } return result; @@ -8896,7 +8918,7 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p, if (same_type_p (to_type, pfn_type)) return pfn; else if (integer_zerop (n) && TREE_CODE (pfn) != CONSTRUCTOR) - return build_reinterpret_cast (to_type, pfn, + return build_reinterpret_cast (input_location, to_type, pfn, complain); } @@ -8930,7 +8952,7 @@ build_ptrmemfunc (tree type, tree pfn, int force, bool c_cast_p, /* Handle null pointer to member function conversions. */ if (null_ptr_cst_p (pfn)) { - pfn = cp_build_c_cast (type, pfn, complain); + pfn = cp_build_c_cast (input_location, type, pfn, complain); return build_ptrmemfunc1 (to_type, integer_zero_node, pfn); @@ -9085,7 +9107,7 @@ convert_for_assignment (tree type, tree rhs, { warning_sentinel w (warn_useless_cast); warning_sentinel w2 (warn_ignored_qualifiers); - rhs = cp_build_c_cast (type, elt, complain); + rhs = cp_build_c_cast (rhs_loc, type, elt, complain); } else rhs = error_mark_node; diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 1dbf8cd89cd..a9b89369f07 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -2228,9 +2228,9 @@ build_m_component_ref (tree datum, tree component, tsubst_flags_t complain) /* Return a tree node for the expression TYPENAME '(' PARMS ')'. */ -tree -build_functional_cast (location_t loc, tree exp, tree parms, - tsubst_flags_t complain) +static tree +build_functional_cast_1 (location_t loc, tree exp, tree parms, + tsubst_flags_t complain) { /* This is either a call to a constructor, or a C cast in C++'s `functional' notation. */ @@ -2319,7 +2319,7 @@ build_functional_cast (location_t loc, tree exp, tree parms, /* This must build a C cast. */ parms = build_x_compound_expr_from_list (parms, ELK_FUNC_CAST, complain); - return cp_build_c_cast (type, parms, complain); + return cp_build_c_cast (loc, type, parms, complain); } /* Prepare to evaluate as a call to a constructor. If this expression @@ -2340,7 +2340,7 @@ build_functional_cast (location_t loc, tree exp, tree parms, conversion is equivalent (in definedness, and if defined in meaning) to the corresponding cast expression. */ if (parms && TREE_CHAIN (parms) == NULL_TREE) - return cp_build_c_cast (type, TREE_VALUE (parms), complain); + return cp_build_c_cast (loc, type, TREE_VALUE (parms), complain); /* [expr.type.conv] @@ -2368,6 +2368,15 @@ build_functional_cast (location_t loc, tree exp, tree parms, return build_cplus_new (type, exp, complain); } + +tree +build_functional_cast (location_t loc, tree exp, tree parms, + tsubst_flags_t complain) +{ + tree result = build_functional_cast_1 (loc, exp, parms, complain); + protected_set_expr_location (result, loc); + return result; +} /* Add new exception specifier SPEC, to the LIST we currently have. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a03407038c8..88c5a051e37 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,57 @@ +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. + 2019-12-09 Lewis Hyatt PR preprocessor/49973 diff --git a/gcc/testsuite/c-c++-common/Wcast-align.c b/gcc/testsuite/c-c++-common/Wcast-align.c index fac1795476c..c296c7fd249 100644 --- a/gcc/testsuite/c-c++-common/Wcast-align.c +++ b/gcc/testsuite/c-c++-common/Wcast-align.c @@ -16,8 +16,8 @@ struct t { double x; } *q; void foo (void) { - y = (c *) x; /* { dg-warning "alignment" } */ - z = (d *) x; /* { dg-warning "alignment" } */ + y = (c *) x; /* { dg-warning "7:cast \[^\n\r]* required alignment of target type" } */ + z = (d *) x; /* { dg-warning "7:cast \[^\n\r]* required alignment of target type" } */ (long long *) p; /* { dg-bogus "alignment" } */ (double *) q; /* { dg-bogus "alignment" } */ } diff --git a/gcc/testsuite/c-c++-common/Wcast-function-type.c b/gcc/testsuite/c-c++-common/Wcast-function-type.c index 81105762ef7..b49da486814 100644 --- a/gcc/testsuite/c-c++-common/Wcast-function-type.c +++ b/gcc/testsuite/c-c++-common/Wcast-function-type.c @@ -24,8 +24,8 @@ void foo (void) { a = (f1 *) f; /* { dg-bogus "incompatible function types" } */ - b = (f2 *) f; /* { dg-warning "incompatible function types" } */ + b = (f2 *) f; /* { dg-warning "7:cast between incompatible function types" } */ c = (f3 *) f; /* { dg-bogus "incompatible function types" } */ - d = (f4 *) f; /* { dg-warning "incompatible function types" } */ + d = (f4 *) f; /* { dg-warning "7:cast between incompatible function types" } */ e = (f5 *) f; /* { dg-bogus "incompatible function types" } */ } diff --git a/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c index a7687a60758..da777794273 100644 --- a/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c +++ b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-1.c @@ -8,5 +8,5 @@ char c; void * f (void) { - return (void *) c; /* { dg-warning "cast to pointer from integer of different size" } */ + return (void *) c; /* { dg-warning "10:cast to pointer from integer of different size" } */ } diff --git a/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c index 5546abb8186..bf2c7b1d323 100644 --- a/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c +++ b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-2.c @@ -8,5 +8,5 @@ char c; void * f (void) { - return (void *) c; /* { dg-warning "cast to pointer from integer of different size" } */ + return (void *) c; /* { dg-warning "10:cast to pointer from integer of different size" } */ } diff --git a/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c index 8df4e1fa4ae..0ac35b2c5bc 100644 --- a/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c +++ b/gcc/testsuite/c-c++-common/Wint-to-pointer-cast-3.c @@ -17,6 +17,6 @@ char g (void) { return (char) p; -/* { dg-warning "cast from pointer to integer of different size" "" { target c } .-1 } */ -/* { dg-error "cast from 'void\\*' to 'char' loses precision" "" { target c++ } .-2 } */ +/* { dg-warning "10:cast from pointer to integer of different size" "" { target c } .-1 } */ +/* { dg-error "10:cast from 'void\\*' to 'char' loses precision" "" { target c++ } .-2 } */ } diff --git a/gcc/testsuite/g++.dg/Wcast-function-type.C b/gcc/testsuite/g++.dg/Wcast-function-type.C index c6494051791..4d3ac33a392 100644 --- a/gcc/testsuite/g++.dg/Wcast-function-type.C +++ b/gcc/testsuite/g++.dg/Wcast-function-type.C @@ -12,6 +12,6 @@ typedef void (S::*MF)(int); void foo (void) { - MF p1 = (MF)&S::foo; /* { dg-warning "pointer to member" } */ + MF p1 = (MF)&S::foo; /* { dg-warning "11:cast between incompatible pointer to member" } */ MF p2 = (MF)&S::bar; /* { dg-bogus "pointer to member" } */ } diff --git a/gcc/testsuite/g++.dg/addr_builtin-1.C b/gcc/testsuite/g++.dg/addr_builtin-1.C index 0c282b1f8cd..eebe54d316f 100644 --- a/gcc/testsuite/g++.dg/addr_builtin-1.C +++ b/gcc/testsuite/g++.dg/addr_builtin-1.C @@ -93,8 +93,8 @@ static F* test_taking_address_of_gcc_builtin () // Expect a diagnostic for an invalid static_cast of a function to // either uintptr_t or enum, rather than one for the argument being // a built-in function, since the former is more relevant than the latter. - a = static_cast(__builtin_trap); // { dg-error "invalid" } - a = static_cast(__builtin_trap); // { dg-error "invalid" } + a = static_cast(__builtin_trap); // { dg-error "7:invalid .static_cast." } + a = static_cast(__builtin_trap); // { dg-error "7:invalid .static_cast." } // Reinterpret cast can cast a function to uintptr_t or enum, // so verify that a diagnostic is issued for the use of a builtin. diff --git a/gcc/testsuite/g++.dg/conversion/const2.C b/gcc/testsuite/g++.dg/conversion/const2.C index fd2be1f4444..cedd3551873 100644 --- a/gcc/testsuite/g++.dg/conversion/const2.C +++ b/gcc/testsuite/g++.dg/conversion/const2.C @@ -7,5 +7,5 @@ typedef int D::*dm; bm bp; void f() { - const_cast(bp); // { dg-error "" } + const_cast(bp); // { dg-error "3:invalid .const_cast." } } diff --git a/gcc/testsuite/g++.dg/conversion/dynamic1.C b/gcc/testsuite/g++.dg/conversion/dynamic1.C index 3c8739c5422..5a2c4be51aa 100644 --- a/gcc/testsuite/g++.dg/conversion/dynamic1.C +++ b/gcc/testsuite/g++.dg/conversion/dynamic1.C @@ -11,5 +11,5 @@ A& bar(); void baz() { - dynamic_cast( bar().foo ); // { dg-error "cannot 'dynamic_cast'" } + dynamic_cast( bar().foo ); // { dg-error "3:cannot 'dynamic_cast'" } } diff --git a/gcc/testsuite/g++.dg/conversion/ptrmem2.C b/gcc/testsuite/g++.dg/conversion/ptrmem2.C index 1dec36bfba8..9e162fa435e 100644 --- a/gcc/testsuite/g++.dg/conversion/ptrmem2.C +++ b/gcc/testsuite/g++.dg/conversion/ptrmem2.C @@ -35,9 +35,9 @@ const int B::*p9 = static_cast(&D::x); const int D::*p10 = static_cast(&B::x); // Invalid conversions which decrease cv-qualification. -int B::*p11 = static_cast(p10); // { dg-error "casts away qualifiers" } -int D::*p12 = static_cast(p9); // { dg-error "casts away qualifiers" } +int B::*p11 = static_cast(p10); // { dg-error "15:.static_cast. from type .const int D::\\*. to type .int B::\\*. casts away qualifiers" } +int D::*p12 = static_cast(p9); // { dg-error "15:.static_cast. from type .const int B::\\*. to type .int D::\\*. casts away qualifiers" } // Attempts to change member type. -float B::*p13 = static_cast(&D::x); // { dg-error "invalid .static_cast." } -float D::*p14 = static_cast(&B::x); // { dg-error "invalid .static_cast." } +float B::*p13 = static_cast(&D::x); // { dg-error "17:invalid .static_cast." } +float D::*p14 = static_cast(&B::x); // { dg-error "17:invalid .static_cast." } diff --git a/gcc/testsuite/g++.dg/conversion/ptrmem3.C b/gcc/testsuite/g++.dg/conversion/ptrmem3.C index 13005e4298e..435a9398ab3 100644 --- a/gcc/testsuite/g++.dg/conversion/ptrmem3.C +++ b/gcc/testsuite/g++.dg/conversion/ptrmem3.C @@ -27,5 +27,5 @@ int (A::*p7)() = static_cast(&D::f); // { dg-error "" } int (D::*p8)() = static_cast(&A::f); // { dg-error "" } // Attempts to change member type. -float (B::*p13)() = static_cast(&D::f); // { dg-error "" } -float (D::*p14)() = static_cast(&B::f); // { dg-error "" } +float (B::*p13)() = static_cast(&D::f); // { dg-error "21:invalid .static_cast." } +float (D::*p14)() = static_cast(&B::f); // { dg-error "21:invalid .static_cast." } diff --git a/gcc/testsuite/g++.dg/conversion/qual3.C b/gcc/testsuite/g++.dg/conversion/qual3.C index 4b466d9ea5d..db93b6b60aa 100644 --- a/gcc/testsuite/g++.dg/conversion/qual3.C +++ b/gcc/testsuite/g++.dg/conversion/qual3.C @@ -24,30 +24,30 @@ f (P p, Q q, Q2 q2, R r, S s, T t) const_cast

(q2); const_cast(p); const_cast(p); - const_cast(p); // { dg-error "invalid .const_cast." } - const_cast

(s); // { dg-error "invalid .const_cast." } - const_cast(q); // { dg-error "invalid .const_cast." } - const_cast(q2); // { dg-error "invalid .const_cast." } - const_cast(s); // { dg-error "invalid .const_cast." } - const_cast(s); // { dg-error "invalid .const_cast." } + const_cast(p); // { dg-error "3:invalid .const_cast." } + const_cast

(s); // { dg-error "3:invalid .const_cast." } + const_cast(q); // { dg-error "3:invalid .const_cast." } + const_cast(q2); // { dg-error "3:invalid .const_cast." } + const_cast(s); // { dg-error "3:invalid .const_cast." } + const_cast(s); // { dg-error "3:invalid .const_cast." } const_cast(s); const_cast(t); - const_cast(q); // { dg-error "invalid .const_cast." } - const_cast(t); // { dg-error "invalid .const_cast." } + const_cast(q); // { dg-error "3:invalid .const_cast." } + const_cast(t); // { dg-error "3:invalid .const_cast." } // Test reinterpret_cast. - reinterpret_cast

(q); // { dg-error "casts away qualifiers" } - reinterpret_cast

(q2); // { dg-error "casts away qualifiers" } + reinterpret_cast

(q); // { dg-error "3:.reinterpret_cast. \[^\n\r]* casts away qualifiers" } + reinterpret_cast

(q2); // { dg-error "3:.reinterpret_cast. \[^\n\r]* casts away qualifiers" } reinterpret_cast(p); reinterpret_cast(p); reinterpret_cast(p); - reinterpret_cast

(s); // { dg-error "casts away qualifiers" } + reinterpret_cast

(s); // { dg-error "3:.reinterpret_cast. \[^\n\r]* casts away qualifiers" } reinterpret_cast(q); reinterpret_cast(q2); reinterpret_cast(s); reinterpret_cast(s); - reinterpret_cast(s); // { dg-error "casts away qualifiers" } + reinterpret_cast(s); // { dg-error "3:.reinterpret_cast. \[^\n\r]* casts away qualifiers" } reinterpret_cast(t); - reinterpret_cast(q); // { dg-error "casts away qualifiers" } + reinterpret_cast(q); // { dg-error "3:.reinterpret_cast. \[^\n\r]* casts away qualifiers" } reinterpret_cast(t); } diff --git a/gcc/testsuite/g++.dg/conversion/reinterpret3.C b/gcc/testsuite/g++.dg/conversion/reinterpret3.C index 62fb91444d4..0ea280f318a 100644 --- a/gcc/testsuite/g++.dg/conversion/reinterpret3.C +++ b/gcc/testsuite/g++.dg/conversion/reinterpret3.C @@ -3,5 +3,5 @@ struct S {}; S s; void f() { - reinterpret_cast(s); // { dg-error "" } + reinterpret_cast(s); // { dg-error "3:invalid cast" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C index da76a3dc7bc..909c34e8be6 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-cast.C @@ -14,11 +14,11 @@ template constexpr bool f () { #if __cplusplus > 201103L - T *p = reinterpret_cast(sizeof (T)); + T *p = reinterpret_cast(sizeof (T)); // { dg-error "not a constant expression" "" { target c++14 } } return p; #else - return *reinterpret_cast(sizeof (T)); + return *reinterpret_cast(sizeof (T)); // { dg-error "not a constant expression" "" { target c++11_only } } #endif } -constexpr bool b = f(); // { dg-error "not a constant expression|in .constexpr. expansion of " } +constexpr bool b = f(); // { dg-message "in .constexpr. expansion of " } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C index ec08f504fab..7aef1c88cc0 100644 --- a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-conv11.C @@ -4,7 +4,7 @@ void foo() { int i; - static_cast([i]{}); // { dg-error "invalid 'static_cast'" } - static_cast([=]{}); // { dg-error "invalid 'static_cast'" } - static_cast([&]{}); // { dg-error "invalid 'static_cast'" } + static_cast([i]{}); // { dg-error "3:invalid 'static_cast'" } + static_cast([=]{}); // { dg-error "3:invalid 'static_cast'" } + static_cast([&]{}); // { dg-error "3:invalid 'static_cast'" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/nullptr04.C b/gcc/testsuite/g++.dg/cpp0x/nullptr04.C index 2b9017865f7..15af84c1c86 100644 --- a/gcc/testsuite/g++.dg/cpp0x/nullptr04.C +++ b/gcc/testsuite/g++.dg/cpp0x/nullptr04.C @@ -4,13 +4,13 @@ __extension__ typedef __INTPTR_TYPE__ intptr_t; -const int n4 = static_cast(nullptr); // { dg-error "invalid 'static_cast' " } -const short int n5 = reinterpret_cast(nullptr); // { dg-error "loses precision" } +const int n4 = static_cast(nullptr); // { dg-error "16:invalid 'static_cast' " } +const short int n5 = reinterpret_cast(nullptr); // { dg-error "22:cast from .std::nullptr_t. to .short int. loses precision" } const intptr_t n6 = reinterpret_cast(nullptr); const intptr_t n7 = (intptr_t)nullptr; decltype(nullptr) mynull = 0; -const int n8 = static_cast(mynull); // { dg-error "invalid 'static_cast' " } -const short int n9 = reinterpret_cast(mynull); // { dg-error "loses precision" } +const int n8 = static_cast(mynull); // { dg-error "16:invalid 'static_cast' " } +const short int n9 = reinterpret_cast(mynull); // { dg-error "22:cast from .std::nullptr_t. to .short int. loses precision" } const intptr_t n10 = reinterpret_cast(mynull); const intptr_t n11 = (intptr_t)mynull; diff --git a/gcc/testsuite/g++.dg/cpp0x/reinterpret_cast2.C b/gcc/testsuite/g++.dg/cpp0x/reinterpret_cast2.C index 59f39324c7c..c173576e287 100644 --- a/gcc/testsuite/g++.dg/cpp0x/reinterpret_cast2.C +++ b/gcc/testsuite/g++.dg/cpp0x/reinterpret_cast2.C @@ -6,5 +6,5 @@ struct S { }; void foo () { - auto a = reinterpret_cast(foo ()); // { dg-error "invalid cast of an rvalue expression of type 'void' to type" } + auto a = reinterpret_cast(foo ()); // { dg-error "12:invalid cast of an rvalue expression of type 'void' to type" } } diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C b/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C index 6dc5abcdcf6..c9c087f1687 100644 --- a/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C +++ b/gcc/testsuite/g++.dg/cpp0x/rv-cast2.C @@ -10,11 +10,11 @@ struct A { }; int main() { const_cast(lval()); - const_cast(xval()); // { dg-error "" } - const_cast(prval()); // { dg-error "" } + const_cast(xval()); // { dg-error "3:invalid .const_cast. of an rvalue" } + const_cast(prval()); // { dg-error "3:invalid .const_cast. of an rvalue" } const_cast(lval()); const_cast(xval()); - const_cast(prval()); // { dg-error "" } + const_cast(prval()); // { dg-error "3:invalid .const_cast. of an rvalue" } const_cast(lval()); const_cast(xval()); const_cast(prval()); diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C index 25721259c6b..fc567441b26 100644 --- a/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C +++ b/gcc/testsuite/g++.dg/cpp1y/lambda-conv1.C @@ -4,10 +4,10 @@ void foo() { int i; - static_cast([i](auto){}); // { dg-error "invalid 'static_cast'" } - static_cast([=](auto){}); // { dg-error "invalid 'static_cast'" } - static_cast([&](auto){}); // { dg-error "invalid 'static_cast'" } - static_cast([i](auto x){ return x; }); // { dg-error "invalid 'static_cast'" } - static_cast([=](auto x){ return x; }); // { dg-error "invalid 'static_cast'" } - static_cast([&](auto x){ return x; }); // { dg-error "invalid 'static_cast'" } + static_cast([i](auto){}); // { dg-error "3:invalid 'static_cast'" } + static_cast([=](auto){}); // { dg-error "3:invalid 'static_cast'" } + static_cast([&](auto){}); // { dg-error "3:invalid 'static_cast'" } + static_cast([i](auto x){ return x; }); // { dg-error "3:invalid 'static_cast'" } + static_cast([=](auto x){ return x; }); // { dg-error "3:invalid 'static_cast'" } + static_cast([&](auto x){ return x; }); // { dg-error "3:invalid 'static_cast'" } } diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type7.C b/gcc/testsuite/g++.dg/cpp1z/noexcept-type7.C index 53276478fbe..aabeeda3856 100644 --- a/gcc/testsuite/g++.dg/cpp1z/noexcept-type7.C +++ b/gcc/testsuite/g++.dg/cpp1z/noexcept-type7.C @@ -10,5 +10,5 @@ void f() NP np; static_cast

(np); - static_cast(p); // { dg-error "" } + static_cast(p); // { dg-error "3:invalid .static_cast." } } diff --git a/gcc/testsuite/g++.dg/cpp2a/array-conv9.C b/gcc/testsuite/g++.dg/cpp2a/array-conv9.C index 82f615db2e7..63318c53e09 100644 --- a/gcc/testsuite/g++.dg/cpp2a/array-conv9.C +++ b/gcc/testsuite/g++.dg/cpp2a/array-conv9.C @@ -8,7 +8,7 @@ void test () { int (&r)[1] = const_cast(arr); - int (&r2)[] = const_cast(arr); // { dg-error "invalid" } + int (&r2)[] = const_cast(arr); // { dg-error "17:invalid .const_cast." } int (&r3)[1] = (int(&)[1]) arr; int (&r4)[] = (int(&)[]) arr; int (&r5)[1] = static_cast(arr); @@ -23,5 +23,5 @@ test () int(*p6)[] = (int(*)[1]) (int(*)[]) &arr; int(*p7)[] = static_cast(&arr); int(*p8)[] = static_cast(&arr); - int(*p9)[] = static_cast(&arr2); // { dg-error "invalid" } + int(*p9)[] = static_cast(&arr2); // { dg-error "16:invalid .static_cast." } } diff --git a/gcc/testsuite/g++.dg/expr/cast11.C b/gcc/testsuite/g++.dg/expr/cast11.C index 01d578a6e18..baafebb3c73 100644 --- a/gcc/testsuite/g++.dg/expr/cast11.C +++ b/gcc/testsuite/g++.dg/expr/cast11.C @@ -13,22 +13,22 @@ struct B { int i; const char c; } b = {}; void f1() { int i = 0; - f((long const)i); // { dg-warning "qualifiers ignored" } - f((int* const)&i); // { dg-warning "qualifiers ignored" } - f((int const* const)&i); // { dg-warning "qualifiers ignored" } - f((long* const)&i); // { dg-warning "qualifiers ignored" } + f((long const)i); // { dg-warning "5:type qualifiers ignored" } + f((int* const)&i); // { dg-warning "5:type qualifiers ignored" } + f((int const* const)&i); // { dg-warning "5:type qualifiers ignored" } + f((long* const)&i); // { dg-warning "5:type qualifiers ignored" } - f(static_cast(i)); // { dg-warning "qualifiers ignored" } - f(reinterpret_cast(&i)); // { dg-warning "qualifiers ignored" } + f(static_cast(i)); // { dg-warning "5:type qualifiers ignored" } + f(reinterpret_cast(&i)); // { dg-warning "5:type qualifiers ignored" } - f(static_cast(&i)); // { dg-warning "qualifiers ignored" } - f(const_cast(&i)); // { dg-warning "qualifiers ignored" } - f(reinterpret_cast(&i)); // { dg-warning "qualifiers ignored" } + f(static_cast(&i)); // { dg-warning "5:type qualifiers ignored" } + f(const_cast(&i)); // { dg-warning "5:type qualifiers ignored" } + f(reinterpret_cast(&i)); // { dg-warning "5:type qualifiers ignored" } using ptrmem = int B::*; - f(static_cast(&B::i)); // { dg-warning "qualifiers ignored" } - f(const_cast(&B::i)); // { dg-warning "qualifiers ignored" } - f(reinterpret_cast(&B::i)); // { dg-warning "qualifiers ignored" } + f(static_cast(&B::i)); // { dg-warning "5:type qualifiers ignored" } + f(const_cast(&B::i)); // { dg-warning "5:type qualifiers ignored" } + f(reinterpret_cast(&B::i)); // { dg-warning "5:type qualifiers ignored" } // No warnings, not a cv-qualified type: using ptrmem2 = const char B::*; diff --git a/gcc/testsuite/g++.dg/expr/static_cast8.C b/gcc/testsuite/g++.dg/expr/static_cast8.C index 6dd7560136c..f8c4525e268 100644 --- a/gcc/testsuite/g++.dg/expr/static_cast8.C +++ b/gcc/testsuite/g++.dg/expr/static_cast8.C @@ -9,9 +9,9 @@ extern C* c; void pointers(C* c, A2* a2, B1* b1) { - (void) static_cast(c); // { dg-error "invalid 'static_cast'" } - (void) static_cast(a2); // { dg-error "invalid 'static_cast'" } - (void) static_cast(b1); // { dg-error "invalid 'static_cast'" } + (void) static_cast(c); // { dg-error "10:invalid 'static_cast'" } + (void) static_cast(a2); // { dg-error "10:invalid 'static_cast'" } + (void) static_cast(b1); // { dg-error "10:invalid 'static_cast'" } } struct D1; // { dg-message "note: class type 'D1' is incomplete" } @@ -21,7 +21,7 @@ struct E2; // { dg-message "note: class type 'E2' is incomplete" } void references(C& c, D2& d2, E1& e1) { - (void) static_cast(c); // { dg-error "invalid 'static_cast'" } - (void) static_cast(d2); // { dg-error "invalid 'static_cast'" } - (void) static_cast(e1); // { dg-error "invalid 'static_cast'" } + (void) static_cast(c); // { dg-error "10:invalid 'static_cast'" } + (void) static_cast(d2); // { dg-error "10:invalid 'static_cast'" } + (void) static_cast(e1); // { dg-error "10:invalid 'static_cast'" } } diff --git a/gcc/testsuite/g++.dg/ext/vector6.C b/gcc/testsuite/g++.dg/ext/vector6.C index 9caf8c2f69a..70e90cd5a81 100644 --- a/gcc/testsuite/g++.dg/ext/vector6.C +++ b/gcc/testsuite/g++.dg/ext/vector6.C @@ -8,5 +8,5 @@ typedef union {__v_4F v; float a[4];} __v4F; void f(void) { __v_4F b; - (reinterpret_cast<__v4F>(b).a)[1] = 1; // { dg-error "" } + (reinterpret_cast<__v4F>(b).a)[1] = 1; // { dg-error "8:invalid cast" } } diff --git a/gcc/testsuite/g++.dg/other/conversion1.C b/gcc/testsuite/g++.dg/other/conversion1.C index e9ddb2b2896..1660443012a 100644 --- a/gcc/testsuite/g++.dg/other/conversion1.C +++ b/gcc/testsuite/g++.dg/other/conversion1.C @@ -13,5 +13,5 @@ int main() { long long m; - (void (QObject::*)()) m; // { dg-error "invalid cast" } + (void (QObject::*)()) m; // { dg-error "3:invalid cast" } } diff --git a/gcc/testsuite/g++.dg/parse/pr26997.C b/gcc/testsuite/g++.dg/parse/pr26997.C index acd1e07be34..be3589cee73 100644 --- a/gcc/testsuite/g++.dg/parse/pr26997.C +++ b/gcc/testsuite/g++.dg/parse/pr26997.C @@ -21,7 +21,7 @@ public: C bar (void) { - (C ())(3); // { dg-error "invalid cast" } + (C ())(3); // { dg-error "3:invalid cast" } return (C ()); } @@ -41,9 +41,9 @@ void foo2 (void) { C ()[2]; (C ())[2]; - (S ())(3); // { dg-error "invalid cast" } - (C())*var; // { dg-error "invalid cast" } - (C())+var; // { dg-error "invalid cast" } + (S ())(3); // { dg-error "3:invalid cast" } + (C())*var; // { dg-error "3:invalid cast" } + (C())+var; // { dg-error "3:invalid cast" } S()(3); (S()(3)); } diff --git a/gcc/testsuite/g++.dg/rtti/no-rtti.C b/gcc/testsuite/g++.dg/rtti/no-rtti.C index fdf2e605274..a8bd78e0f39 100644 --- a/gcc/testsuite/g++.dg/rtti/no-rtti.C +++ b/gcc/testsuite/g++.dg/rtti/no-rtti.C @@ -14,5 +14,5 @@ A* f(); int main() { - B* b = dynamic_cast(f()); // { dg-error "" } + B* b = dynamic_cast(f()); // { dg-error "11:.dynamic_cast. not permitted" } } diff --git a/gcc/testsuite/g++.dg/tc1/dr137.C b/gcc/testsuite/g++.dg/tc1/dr137.C index bc1beb021bb..3b1d260ea4a 100644 --- a/gcc/testsuite/g++.dg/tc1/dr137.C +++ b/gcc/testsuite/g++.dg/tc1/dr137.C @@ -9,5 +9,5 @@ const void* v; void foo(void) { (void)static_cast(v); - (void)static_cast(v); // { dg-error "" "static_cast cannot remove cv qualifiers" } + (void)static_cast(v); // { dg-error "9:.static_cast. from type .const void\\*. to type .A\\*. casts away qualifiers" "static_cast cannot remove cv qualifiers" } } diff --git a/gcc/testsuite/g++.dg/template/cast4.C b/gcc/testsuite/g++.dg/template/cast4.C index 2f46c7189eb..93ec5d86e60 100644 --- a/gcc/testsuite/g++.dg/template/cast4.C +++ b/gcc/testsuite/g++.dg/template/cast4.C @@ -1,4 +1,4 @@ template void f() { - static_cast(42); // { dg-error "static_cast" } + static_cast(42); // { dg-error "3:invalid .static_cast." } } diff --git a/gcc/testsuite/g++.dg/warn/Wcast-qual1.C b/gcc/testsuite/g++.dg/warn/Wcast-qual1.C index e6ad4f6a06d..23be6fa5c4d 100644 --- a/gcc/testsuite/g++.dg/warn/Wcast-qual1.C +++ b/gcc/testsuite/g++.dg/warn/Wcast-qual1.C @@ -3,5 +3,5 @@ int main(int, char**) { const int foo[2] = {1,1}; - ((int*)foo)[0] = 0; // { dg-warning "cast" } + ((int*)foo)[0] = 0; // { dg-warning "4:cast" } } diff --git a/gcc/testsuite/g++.dg/warn/Wcast-qual2.C b/gcc/testsuite/g++.dg/warn/Wcast-qual2.C index 23dbb4d39b0..45db74bbef7 100644 --- a/gcc/testsuite/g++.dg/warn/Wcast-qual2.C +++ b/gcc/testsuite/g++.dg/warn/Wcast-qual2.C @@ -1,4 +1,4 @@ // PR c++/50956 // { dg-options "-Wcast-qual" } -void* p = (void*)"txt"; // { dg-warning "cast" } +void* p = (void*)"txt"; // { dg-warning "11:cast" } diff --git a/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C b/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C index 8cc5966eda8..3c32edba8ce 100644 --- a/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C +++ b/gcc/testsuite/g++.dg/warn/Wconditionally-supported-1.C @@ -17,9 +17,9 @@ void foo () PV pv; PO po; - pf = reinterpret_cast (pv); // { dg-warning "conditionally-supported" } - pv = reinterpret_cast (pf); // { dg-warning "conditionally-supported" } + pf = reinterpret_cast (pv); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" } + pv = reinterpret_cast (pf); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" } - pf = reinterpret_cast (po); // { dg-warning "conditionally-supported" } - po = reinterpret_cast (pf); // { dg-warning "conditionally-supported" } + pf = reinterpret_cast (po); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" } + po = reinterpret_cast (pf); // { dg-warning "8:casting between pointer-to-function and pointer-to-object is conditionally-supported" } } diff --git a/gcc/testsuite/g++.dg/warn/Wuseless-cast.C b/gcc/testsuite/g++.dg/warn/Wuseless-cast.C index 6f0e2cfb0b2..2fd6bc45102 100644 --- a/gcc/testsuite/g++.dg/warn/Wuseless-cast.C +++ b/gcc/testsuite/g++.dg/warn/Wuseless-cast.C @@ -64,28 +64,28 @@ void f() { int n; - (int)(n); // { dg-warning "useless cast" } - static_cast(n); // { dg-warning "useless cast" } - reinterpret_cast(n); // { dg-warning "useless cast" } + (int)(n); // { dg-warning "3:useless cast" } + static_cast(n); // { dg-warning "3:useless cast" } + reinterpret_cast(n); // { dg-warning "3:useless cast" } - (int*)(&n); // { dg-warning "useless cast" } - const_cast(&n); // { dg-warning "useless cast" } - static_cast(&n); // { dg-warning "useless cast" } - reinterpret_cast(&n); // { dg-warning "useless cast" } + (int*)(&n); // { dg-warning "3:useless cast" } + const_cast(&n); // { dg-warning "3:useless cast" } + static_cast(&n); // { dg-warning "3:useless cast" } + reinterpret_cast(&n); // { dg-warning "3:useless cast" } int& m = n; - (int&)(m); // { dg-warning "useless cast" } - const_cast(m); // { dg-warning "useless cast" } - static_cast(m); // { dg-warning "useless cast" } - reinterpret_cast(m); // { dg-warning "useless cast" } + (int&)(m); // { dg-warning "3:useless cast" } + const_cast(m); // { dg-warning "3:useless cast" } + static_cast(m); // { dg-warning "3:useless cast" } + reinterpret_cast(m); // { dg-warning "3:useless cast" } tmpl_f1(m); - (int&)(n); // { dg-warning "useless cast" } - const_cast(n); // { dg-warning "useless cast" } - static_cast(n); // { dg-warning "useless cast" } - reinterpret_cast(n); // { dg-warning "useless cast" } + (int&)(n); // { dg-warning "3:useless cast" } + const_cast(n); // { dg-warning "3:useless cast" } + static_cast(n); // { dg-warning "3:useless cast" } + reinterpret_cast(n); // { dg-warning "3:useless cast" } tmpl_f2(n); @@ -100,30 +100,30 @@ void f() A a; - (A)(a); // { dg-warning "useless cast" } - static_cast(a); // { dg-warning "useless cast" } + (A)(a); // { dg-warning "3:useless cast" } + static_cast(a); // { dg-warning "3:useless cast" } - (A*)(&a); // { dg-warning "useless cast" } - const_cast(&a); // { dg-warning "useless cast" } - static_cast(&a); // { dg-warning "useless cast" } - reinterpret_cast(&a); // { dg-warning "useless cast" } - dynamic_cast(&a); // { dg-warning "useless cast" } + (A*)(&a); // { dg-warning "3:useless cast" } + const_cast(&a); // { dg-warning "3:useless cast" } + static_cast(&a); // { dg-warning "3:useless cast" } + reinterpret_cast(&a); // { dg-warning "3:useless cast" } + dynamic_cast(&a); // { dg-warning "3:useless cast" } A& b = a; - (A&)(b); // { dg-warning "useless cast" } - const_cast(b); // { dg-warning "useless cast" } - static_cast(b); // { dg-warning "useless cast" } - static_cast(b); // { dg-warning "useless cast" } - dynamic_cast(b); // { dg-warning "useless cast" } + (A&)(b); // { dg-warning "3:useless cast" } + const_cast(b); // { dg-warning "3:useless cast" } + static_cast(b); // { dg-warning "3:useless cast" } + static_cast(b); // { dg-warning "3:useless cast" } + dynamic_cast(b); // { dg-warning "3:useless cast" } tmpl_f3(b); - (A&)(a); // { dg-warning "useless cast" } - const_cast(a); // { dg-warning "useless cast" } - static_cast(a); // { dg-warning "useless cast" } - reinterpret_cast(a); // { dg-warning "useless cast" } - dynamic_cast(a); // { dg-warning "useless cast" } + (A&)(a); // { dg-warning "3:useless cast" } + const_cast(a); // { dg-warning "3:useless cast" } + static_cast(a); // { dg-warning "3:useless cast" } + reinterpret_cast(a); // { dg-warning "3:useless cast" } + dynamic_cast(a); // { dg-warning "3:useless cast" } tmpl_f4(a); } diff --git a/gcc/testsuite/g++.dg/warn/pr35711.C b/gcc/testsuite/g++.dg/warn/pr35711.C index 653269c0e79..2a71d32bd09 100644 --- a/gcc/testsuite/g++.dg/warn/pr35711.C +++ b/gcc/testsuite/g++.dg/warn/pr35711.C @@ -4,5 +4,5 @@ int* foo (volatile int *p) { - return (int*)p; // { dg-warning "cast from type 'volatile int\\*' to type 'int\\*' casts away qualifiers" } + return (int*)p; // { dg-warning "10:cast from type 'volatile int\\*' to type 'int\\*' casts away qualifiers" } } diff --git a/gcc/testsuite/g++.old-deja/g++.bugs/900227_01.C b/gcc/testsuite/g++.old-deja/g++.bugs/900227_01.C index b441eff650a..c42557a5c16 100644 --- a/gcc/testsuite/g++.old-deja/g++.bugs/900227_01.C +++ b/gcc/testsuite/g++.old-deja/g++.bugs/900227_01.C @@ -33,7 +33,7 @@ int main (); -short s = (short) &main; // { dg-error "loses precision" "lose" { xfail h8*-*-* xstormy16-*-* } } -char c = (char) &main; // { dg-error "loses precision" "lose" } +short s = (short) &main; // { dg-error "11:cast \[^\n\r]* loses precision" "lose" { xfail h8*-*-* xstormy16-*-* } } +char c = (char) &main; // { dg-error "10:cast \[^\n\r]* loses precision" "lose" } int main () { return 0; } diff --git a/gcc/testsuite/g++.old-deja/g++.bugs/900404_07.C b/gcc/testsuite/g++.old-deja/g++.bugs/900404_07.C index 19791bfdbac..eb2bf95c07a 100644 --- a/gcc/testsuite/g++.old-deja/g++.bugs/900404_07.C +++ b/gcc/testsuite/g++.old-deja/g++.bugs/900404_07.C @@ -14,5 +14,5 @@ array_type *ap; void foo () { - int i = *((array_type) *ap); /* { dg-error "" } missed */ + int i = *((array_type) *ap); /* { dg-error "13:ISO C\\+\\+ forbids casting to an array type" } missed */ } diff --git a/gcc/testsuite/g++.old-deja/g++.jason/overload1.C b/gcc/testsuite/g++.old-deja/g++.jason/overload1.C index 36f9cac468b..2aa27ae7bde 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/overload1.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/overload1.C @@ -8,5 +8,5 @@ struct A { struct B: public A { }; void bar (A& a) { - B* bp = (B*)a; // { dg-error "" } + B* bp = (B*)a; // { dg-error "11:invalid cast" } } diff --git a/gcc/testsuite/g++.old-deja/g++.jason/rfg26.C b/gcc/testsuite/g++.old-deja/g++.jason/rfg26.C index 2b7e06085a4..43314fd16d1 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/rfg26.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/rfg26.C @@ -6,5 +6,5 @@ FTYPE f; /* ok */ void test_0 () { - (FTYPE) f; /* { dg-error "" } casting to function type */ + (FTYPE) f; /* { dg-error "5:invalid cast to function type" } casting to function type */ } diff --git a/gcc/testsuite/g++.old-deja/g++.jason/rvalue3.C b/gcc/testsuite/g++.old-deja/g++.jason/rvalue3.C index 58cdad5d27c..49191c9e408 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/rvalue3.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/rvalue3.C @@ -2,5 +2,5 @@ int main () { int i; - int &ir = (int&)(int)i; // { dg-error "" } casting rvalue to reference type + int &ir = (int&)(int)i; // { dg-error "14:invalid cast of an rvalue expression" } casting rvalue to reference type } diff --git a/gcc/testsuite/g++.old-deja/g++.jason/warning2.C b/gcc/testsuite/g++.old-deja/g++.jason/warning2.C index 6298587e8ff..b17e06fcafe 100644 --- a/gcc/testsuite/g++.old-deja/g++.jason/warning2.C +++ b/gcc/testsuite/g++.old-deja/g++.jason/warning2.C @@ -10,5 +10,5 @@ struct B: public A { void f () { } }; int main() { B* bp; - A& ar = (A&)bp; // { dg-warning "" } + A& ar = (A&)bp; // { dg-warning "11:casting .B\\*. to .A&. does not dereference pointer" } } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/dyncast4.C b/gcc/testsuite/g++.old-deja/g++.mike/dyncast4.C index 75e9771b53b..4bcec2cd9af 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/dyncast4.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/dyncast4.C @@ -1,5 +1,5 @@ // { dg-do assemble } int main() { int* d; - dynamic_cast(d); // { dg-error "" } + dynamic_cast(d); // { dg-error "3:cannot .dynamic_cast." } } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/dyncast6.C b/gcc/testsuite/g++.old-deja/g++.mike/dyncast6.C index 60065a496f0..adfe13669a3 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/dyncast6.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/dyncast6.C @@ -9,5 +9,5 @@ public: class B : public A { }; void x (A& a) { - const B& b1 = dynamic_cast((const A&)a); // { dg-error "" } opps + const B& b1 = dynamic_cast((const A&)a); // { dg-error "17:cannot .dynamic_cast." } opps } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p11482.C b/gcc/testsuite/g++.old-deja/g++.mike/p11482.C index ff5e7bad223..1a322049222 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p11482.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p11482.C @@ -6,5 +6,5 @@ void *vp; enum E { bad, ok } e; void foo() { - e = (E)vp; // { dg-error "" } + e = (E)vp; // { dg-error "7:invalid cast" } } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p2573.C b/gcc/testsuite/g++.old-deja/g++.mike/p2573.C index 0906979c3b6..b197a2cef64 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p2573.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p2573.C @@ -9,7 +9,9 @@ public: }; char *X::add() { - char *f1 = (char *) &key; // { dg-error "" } - char *f2 = (char *) &vkey; // { dg-error "" } + char *f1 = (char *) &key; // { dg-error "14:invalid cast" } + // { dg-error "24:ISO C\\+\\+ forbids taking the address" "" { target *-*-* } .-1 } + char *f2 = (char *) &vkey; // { dg-error "14:invalid cast" } + // { dg-error "24:ISO C\\+\\+ forbids taking the address" "" { target *-*-* } .-1 } return f1; } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p2855.C b/gcc/testsuite/g++.old-deja/g++.mike/p2855.C index 3f269d276d0..48a3fe42f45 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p2855.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p2855.C @@ -16,6 +16,6 @@ Ctest::operator const char *() const int main() { Ctest obj; - char* temp = (char *)obj; // { dg-error "invalid cast" } + char* temp = (char *)obj; // { dg-error "16:invalid cast" } temp[0] = '\0'; } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p7476.C b/gcc/testsuite/g++.old-deja/g++.mike/p7476.C index 04d77880f93..95f5860ca6c 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p7476.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p7476.C @@ -16,5 +16,5 @@ void HeapTracked::isObjectAllocation(HeapTracked *ptr) void HeapTracked::isObjectAllocation(const HeapTracked *ptr) { const_cast(dynamic_cast(ptr)); - dynamic_cast(ptr); // { dg-error "" } + dynamic_cast(ptr); // { dg-error "3:cannot .dynamic_cast." } } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p8039.C b/gcc/testsuite/g++.old-deja/g++.mike/p8039.C index 4dfb556eaf2..70d36385cb2 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p8039.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p8039.C @@ -11,5 +11,5 @@ extern void bar(int*); int main() { int (C::*mfp)() = &C::func; - bar((int*)mfp); // { dg-error "" } no clear semantics + bar((int*)mfp); // { dg-error "7:invalid cast" } no clear semantics } diff --git a/gcc/testsuite/g++.old-deja/g++.other/cast2.C b/gcc/testsuite/g++.old-deja/g++.other/cast2.C index 7e99ead65e1..6e3d089cb7c 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/cast2.C +++ b/gcc/testsuite/g++.old-deja/g++.other/cast2.C @@ -10,8 +10,9 @@ int main() typedef void (A::*F)(); F p; - const_cast(a); // { dg-error "" } const_cast requires pointer/ref types - const_cast(p); // { dg-error "" } const_cast requires pointer/ref types - const_cast(&main); // { dg-error "" } function type in const_cast - const_cast(main); // { dg-error "" } function type in const_cast + const_cast(a); // { dg-error "3:invalid use of .const_cast." } const_cast requires pointer/ref types + const_cast(p); // { dg-error "3:invalid use of .const_cast." } const_cast requires pointer/ref types + const_cast(&main); // { dg-error "3:invalid use of .const_cast." } function type in const_cast + // { dg-error "26:ISO C\\+\\+ forbids taking address" "" { target *-*-* } .-1 } + const_cast(main); // { dg-error "3:invalid use of .const_cast." } function type in const_cast } diff --git a/gcc/testsuite/g++.old-deja/g++.other/cast3.C b/gcc/testsuite/g++.old-deja/g++.other/cast3.C index 15a27bb6cbf..9d2f172fea3 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/cast3.C +++ b/gcc/testsuite/g++.old-deja/g++.other/cast3.C @@ -21,24 +21,24 @@ void fn (void *p, void const *cp, Y *yp, Y const *ycp, Z *zp, Z const *zcp) static_cast (p); static_cast (p); - static_cast (cp); // { dg-error "" } lose const + static_cast (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .X\\*. casts away qualifiers" } lose const static_cast (cp); - static_cast (cp); // { dg-error "" } lose const + static_cast (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .int\\*. casts away qualifiers" } lose const static_cast (cp); - static_cast (cp); // { dg-error "" } lose const - static_cast (cp); // { dg-error "" } lose const + static_cast (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .int\\*\\*. casts away qualifiers" } lose const + static_cast (cp); // { dg-error "3:.static_cast. from type .const void\\*. to type .const int\\*\\*. casts away qualifiers" } lose const static_cast (cp); static_cast (cp); static_cast (yp); static_cast (yp); - static_cast (ycp); // { dg-error "" } lose const + static_cast (ycp); // { dg-error "3:.static_cast. from type .const Y\\*. to type .Z\\*. casts away qualifiers" } lose const static_cast (ycp); static_cast (zp); static_cast (zp); - static_cast (zcp); // { dg-error "" } lose const + static_cast (zcp); // { dg-error "3:invalid .static_cast. from type .const Z\\*. to type .Y\\*." } lose const static_cast (zcp); } diff --git a/gcc/testsuite/g++.old-deja/g++.other/dcast1.C b/gcc/testsuite/g++.old-deja/g++.other/dcast1.C index 830def8cbc9..353e2afe877 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/dcast1.C +++ b/gcc/testsuite/g++.old-deja/g++.other/dcast1.C @@ -10,6 +10,6 @@ extern volatile C& cr; void f () { - dynamic_cast(cp); // { dg-error "" } cannot dynamic_cast - dynamic_cast(cr); // { dg-error "" } cannot dynamic_cast + dynamic_cast(cp); // { dg-error "3:cannot .dynamic_cast." } cannot dynamic_cast + dynamic_cast(cr); // { dg-error "3:cannot .dynamic_cast." } cannot dynamic_cast } diff --git a/gcc/testsuite/g++.old-deja/g++.other/dcast2.C b/gcc/testsuite/g++.old-deja/g++.other/dcast2.C index 0f08e066e66..85f1ececd7a 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/dcast2.C +++ b/gcc/testsuite/g++.old-deja/g++.other/dcast2.C @@ -11,7 +11,7 @@ struct D : public B { void foo() { B x; - dynamic_cast(&x); // { dg-warning "" } will never succeed + dynamic_cast(&x); // { dg-warning "3:.dynamic_cast" } will never succeed B* p = &x; dynamic_cast(p); } diff --git a/libcc1/ChangeLog b/libcc1/ChangeLog index 169a0a9eeeb..b288fc92b0c 100644 --- a/libcc1/ChangeLog +++ b/libcc1/ChangeLog @@ -1,3 +1,8 @@ +2019-12-09 Paolo Carlini + + * libcp1plugin.cc (plugin_build_cast_expr): Adjust build_cast + declaration. + 2019-12-05 Paolo Carlini * libcp1plugin.cc (plugin_build_expression_list_expr): Adjust diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc index c728310618f..aa9844af9d3 100644 --- a/libcc1/libcp1plugin.cc +++ b/libcc1/libcp1plugin.cc @@ -3064,7 +3064,8 @@ plugin_build_cast_expr (cc1_plugin::connection *self, gcc_expr operand2) { plugin_context *ctx = static_cast (self); - tree (*build_cast)(tree type, tree expr, tsubst_flags_t complain) = NULL; + tree (*build_cast)(location_t loc, tree type, tree expr, + tsubst_flags_t complain) = NULL; tree type = convert_in (operand1); tree expr = convert_in (operand2); @@ -3101,7 +3102,7 @@ plugin_build_cast_expr (cc1_plugin::connection *self, if (!template_dependent_p) processing_template_decl--; - tree val = build_cast (type, expr, tf_error); + tree val = build_cast (input_location, type, expr, tf_error); if (template_dependent_p) processing_template_decl--; -- 2.30.2