summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2019-12-09 20:28:39 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2019-12-09 20:28:39 +0000
commitca6932ad0ccbbbe3c788cd71595d9a25b8ae0d20 (patch)
treeab35bcb3daba1f0f37edbaa49c7d876b4d1cfa69 /gcc/cp
parentee9256409f21eab5df5076e46d220d6a0b995f79 (diff)
downloadgcc-ca6932ad0ccbbbe3c788cd71595d9a25b8ae0d20.tar.gz
typeck.c (check_for_casting_away_constness): Add location_t parameter and use it.
gcc/cp 2019-12-09 Paolo Carlini <paolo.carlini@oracle.com> * 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 <paolo.carlini@oracle.com> * libcp1plugin.cc (plugin_build_cast_expr): Adjust build_cast declaration. gcc/testsuite 2019-12-09 Paolo Carlini <paolo.carlini@oracle.com> * 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
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog39
-rw-r--r--gcc/cp/cp-tree.h18
-rw-r--r--gcc/cp/decl.c3
-rw-r--r--gcc/cp/method.c9
-rw-r--r--gcc/cp/parser.c38
-rw-r--r--gcc/cp/pt.c8
-rw-r--r--gcc/cp/rtti.c38
-rw-r--r--gcc/cp/semantics.c21
-rw-r--r--gcc/cp/tree.c6
-rw-r--r--gcc/cp/typeck.c238
-rw-r--r--gcc/cp/typeck2.c19
11 files changed, 269 insertions, 168 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 <paolo.carlini@oracle.com>
+
+ * 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 <jakub@redhat.com>
* 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 <int *> (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 <int *> (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_s, va_gc> *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, "%<dynamic_cast<%#T>(%#D)%> can never succeed",
- type, old_expr);
+ warning_at (loc, 0,
+ "%<dynamic_cast<%#T>(%#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, "%<dynamic_cast<%#T>(%#D)%> can never succeed",
- type, op);
+ warning_at (loc, 0,
+ "%<dynamic_cast<%#T>(%#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 ("%<dynamic_cast%> not permitted with %<-fno-rtti%>");
+ error_at (loc,
+ "%<dynamic_cast%> 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 %<dynamic_cast%> %qE (of type %q#T) to type %q#T (%s)",
- old_expr, TREE_TYPE (old_expr), type, errstr);
+ error_at (loc, "cannot %<dynamic_cast%> %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 ("%<static_cast%> from type %qT to type %qT casts away "
- "qualifiers",
- src_type, dest_type);
+ error_at (loc, "%<static_cast%> from type %qT to type %qT casts "
+ "away qualifiers",
+ src_type, dest_type);
return true;
-
+
case REINTERPRET_CAST_EXPR:
if (complain & tf_error)
- error ("%<reinterpret_cast%> from type %qT to type %qT casts away "
- "qualifiers",
- src_type, dest_type);
+ error_at (loc, "%<reinterpret_cast%> 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<TYPE>(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 %<static_cast%> from type %qT to type %qT",
- TREE_TYPE (expr), type);
+ error_at (loc, "invalid %<static_cast%> 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 %<const_cast%> with type %qT, "
- "which is not a pointer, "
- "reference, nor a pointer-to-data-member type", dst_type);
+ error_at (loc, "invalid use of %<const_cast%> 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 %<const_cast%> 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 %<const_cast%> 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 %<const_cast%> of an rvalue of type %qT "
- "to type %qT",
- src_type, dst_type);
- return error_mark_node;
+ error_at (loc, "invalid %<const_cast%> 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 %<const_cast%> from type %qT to type %qT",
- src_type, dst_type);
+ error_at (loc, "invalid %<const_cast%> 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.