[C++ PATCH] Fix -Wreturn-local-addr regression (PR c++/77591)
Jakub Jelinek
jakub@redhat.com
Thu Nov 24 21:47:00 GMT 2016
Hi!
Delayed folding caused following regression where we no longer warn about
returning reference to local variable.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?
2016-11-24 Jakub Jelinek <jakub@redhat.com>
PR c++/77591
* typeck.c (maybe_warn_about_returning_address_of_local): Optimize
whats_returned through fold_for_warn.
* g++.dg/cpp1y/pr77591.C: New test.
--- gcc/cp/typeck.c.jj 2016-11-15 09:57:00.000000000 +0100
+++ gcc/cp/typeck.c 2016-11-24 11:37:30.732109019 +0100
@@ -8612,7 +8612,7 @@ static bool
maybe_warn_about_returning_address_of_local (tree retval)
{
tree valtype = TREE_TYPE (DECL_RESULT (current_function_decl));
- tree whats_returned = retval;
+ tree whats_returned = fold_for_warn (retval);
for (;;)
{
--- gcc/testsuite/g++.dg/cpp1y/pr77591.C.jj 2016-11-24 11:41:03.867436090 +0100
+++ gcc/testsuite/g++.dg/cpp1y/pr77591.C 2016-11-24 11:42:04.428676591 +0100
@@ -0,0 +1,19 @@
+// PR c++/77591
+// { dg-do compile { target c++14 } }
+// { dg-options "-O0 -Wreturn-local-addr" }
+
+class A { };
+
+decltype(auto)
+foo ()
+{
+ A c; // { dg-warning "reference to local variable 'c' returned" }
+ return (c);
+}
+
+decltype(auto)
+bar ()
+{
+ A c; // { dg-warning "reference to local variable 'c' returned" }
+ return 1==1 ? c : c;
+}
Jakub
More information about the Gcc-patches
mailing list