diff options
author | Jason Merrill <jason@redhat.com> | 2020-02-07 17:14:11 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2020-02-08 11:14:58 -0500 |
commit | 61f5369f7ecf1eff9cd7a7016324d60eec338806 (patch) | |
tree | c0b09388b721cc06ee110064b69953e4df6c4fd4 /gcc | |
parent | c151a342b8bae48ce4c864e67913bc3a0346c4c7 (diff) | |
download | gcc-61f5369f7ecf1eff9cd7a7016324d60eec338806.zip gcc-61f5369f7ecf1eff9cd7a7016324d60eec338806.tar.gz gcc-61f5369f7ecf1eff9cd7a7016324d60eec338806.tar.bz2 |
c++: Fix -Wreturn-local-addr location.
* typeck.c (maybe_warn_about_returning_address_of_local): Add
location parameter.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 13 |
2 files changed, 10 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a0542b2..0894457 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 2020-02-08 Jason Merrill <jason@redhat.com> + * typeck.c (maybe_warn_about_returning_address_of_local): Add + location parameter. + * typeck2.c (process_init_constructor): Also clear TREE_SIDE_EFFECTS if appropriate. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 5964c34..c0c98da 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -58,7 +58,7 @@ static tree pointer_diff (location_t, tree, tree, tree, tsubst_flags_t, tree *); static tree get_delta_difference (tree, tree, bool, bool, tsubst_flags_t); static void casts_away_constness_r (tree *, tree *, tsubst_flags_t); static bool casts_away_constness (tree, tree, tsubst_flags_t); -static bool maybe_warn_about_returning_address_of_local (tree); +static bool maybe_warn_about_returning_address_of_local (tree, location_t = UNKNOWN_LOCATION); static void error_args_num (location_t, tree, bool); static int convert_arguments (tree, vec<tree, va_gc> **, tree, int, tsubst_flags_t); @@ -9466,11 +9466,12 @@ convert_for_initialization (tree exp, tree type, tree rhs, int flags, temporary give an appropriate warning and return true. */ static bool -maybe_warn_about_returning_address_of_local (tree retval) +maybe_warn_about_returning_address_of_local (tree retval, location_t loc) { tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl)); tree whats_returned = fold_for_warn (retval); - location_t loc = cp_expr_loc_or_input_loc (retval); + if (!loc) + loc = cp_expr_loc_or_input_loc (retval); for (;;) { @@ -9504,7 +9505,7 @@ maybe_warn_about_returning_address_of_local (tree retval) || is_std_forward_p (whats_returned))) { tree arg = CALL_EXPR_ARG (whats_returned, 0); - return maybe_warn_about_returning_address_of_local (arg); + return maybe_warn_about_returning_address_of_local (arg, loc); } if (TREE_CODE (whats_returned) != ADDR_EXPR) @@ -9550,7 +9551,7 @@ maybe_warn_about_returning_address_of_local (tree retval) if (TYPE_REF_P (TREE_TYPE (base))) { if (tree init = DECL_INITIAL (base)) - return maybe_warn_about_returning_address_of_local (init); + return maybe_warn_about_returning_address_of_local (init, loc); else return false; } @@ -10077,7 +10078,7 @@ check_return_expr (tree retval, bool *no_warning) retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval, TREE_OPERAND (retval, 0)); else if (!processing_template_decl - && maybe_warn_about_returning_address_of_local (retval) + && maybe_warn_about_returning_address_of_local (retval, loc) && INDIRECT_TYPE_P (valtype)) retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval, build_zero_cst (TREE_TYPE (retval))); |