From d969783705f55506c111e4f4d0342b09ef301ea2 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 19 Oct 2017 16:24:39 +0200 Subject: [PATCH] re PR c++/82600 (Address of local variable returned [-Werror=return-local-addr] when building mozilla-central) PR c++/82600 * typeck.c (check_return_expr): Don't call maybe_warn_about_returning_address_of_local in templates. * g++.dg/warn/Wreturn-local-addr-4.C: New test. From-SVN: r253899 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ .../g++.dg/warn/Wreturn-local-addr-4.C | 18 ++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wreturn-local-addr-4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index daf302fc349..9592c83be26 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-10-19 Jakub Jelinek + + PR c++/82600 + * typeck.c (check_return_expr): Don't call + maybe_warn_about_returning_address_of_local in templates. + 2017-10-17 Nathan Sidwell PR c++/82560 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 08b2ae555e6..19fbe3c4a4a 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9228,7 +9228,8 @@ check_return_expr (tree retval, bool *no_warning) && TREE_CODE (TREE_OPERAND (retval, 1)) == AGGR_INIT_EXPR) retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval, TREE_OPERAND (retval, 0)); - else if (maybe_warn_about_returning_address_of_local (retval)) + else if (!processing_template_decl + && maybe_warn_about_returning_address_of_local (retval)) retval = build2 (COMPOUND_EXPR, TREE_TYPE (retval), retval, build_zero_cst (TREE_TYPE (retval))); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1488f6fc03b..3b2f638dba7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-10-19 Jakub Jelinek + + PR c++/82600 + * g++.dg/warn/Wreturn-local-addr-4.C: New test. + 2017-10-19 Eric Botcazou * gcc.dg/debug/dwarf2/sso.c: Rename into... diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-local-addr-4.C b/gcc/testsuite/g++.dg/warn/Wreturn-local-addr-4.C new file mode 100644 index 00000000000..492dcb9e76f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wreturn-local-addr-4.C @@ -0,0 +1,18 @@ +// PR c++/82600 +// { dg-do compile } + +void *b[10]; + +template +void ** +foo (int x) +{ + void **a = b; // { dg-bogus "address of local variable 'a' returned" } + return &a[x]; +} + +void ** +bar (int x) +{ + return foo <0> (x); +} -- 2.30.2