From: Jakub Jelinek Date: Mon, 28 Nov 2016 15:21:53 +0000 (+0100) Subject: re PR c++/77591 (decltype(auto) and ternary operator allow returning local reference... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f4bb5c171e3bcb244f90dfee5aae6e2bc9f92029;p=gcc.git re PR c++/77591 (decltype(auto) and ternary operator allow returning local reference without a warning) 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. From-SVN: r242924 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c6bc06fc241..f442a7a83f0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2016-11-28 Jakub Jelinek + + PR c++/77591 + * typeck.c (maybe_warn_about_returning_address_of_local): Optimize + whats_returned through fold_for_warn. + 2016-11-27 Jason Merrill PR c++/77907 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 6f9ad0ed3cb..68fe19eeadb 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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 (;;) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b69d554f4ea..1444448c3bc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-28 Jakub Jelinek + + PR c++/77591 + * g++.dg/cpp1y/pr77591.C: New test. + 2016-11-28 David Edelsohn * gcc.dg/torture/pr78515.c: Ignore ABI extension warning. diff --git a/gcc/testsuite/g++.dg/cpp1y/pr77591.C b/gcc/testsuite/g++.dg/cpp1y/pr77591.C new file mode 100644 index 00000000000..8f9e28c8501 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/pr77591.C @@ -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; +}