diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2014-07-31 11:33:58 +0200 |
---|---|---|
committer | Marc Glisse <glisse@gcc.gnu.org> | 2014-07-31 09:33:58 +0000 |
commit | b4dfdc11a5440c5aaf0a86d011facaddc61806be (patch) | |
tree | 35e40a78855886e1ee834f1472e67c904d487f62 /gcc/c | |
parent | 3e50df4de7f0daea8b3f6682cfe5f16398b4f155 (diff) | |
download | gcc-b4dfdc11a5440c5aaf0a86d011facaddc61806be.zip gcc-b4dfdc11a5440c5aaf0a86d011facaddc61806be.tar.gz gcc-b4dfdc11a5440c5aaf0a86d011facaddc61806be.tar.bz2 |
re PR c++/60517 (warning/error for taking address of member of a temporary object)
2014-07-31 Marc Glisse <marc.glisse@inria.fr>
PR c++/60517
gcc/c/
* c-typeck.c (c_finish_return): Return 0 instead of the address of
a local variable.
gcc/cp/
* typeck.c (maybe_warn_about_returning_address_of_local): Return
whether it is returning the address of a local variable.
(check_return_expr): Return 0 instead of the address of a local
variable.
gcc/c-family/
* c.opt (-Wreturn-local-addr): Move to common.opt.
gcc/
* common.opt (-Wreturn-local-addr): Moved from c.opt.
* gimple-ssa-isolate-paths.c: Include diagnostic-core.h and intl.h.
(isolate_path): New argument to avoid inserting a trap.
(find_implicit_erroneous_behaviour): Handle returning the address
of a local variable.
(find_explicit_erroneous_behaviour): Likewise.
gcc/testsuite/
* c-c++-common/addrtmp.c: New file.
* c-c++-common/uninit-G.c: Adapt.
From-SVN: r213323
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 8 |
2 files changed, 12 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index b5e7a17..aec8cf1 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2014-07-31 Marc Glisse <marc.glisse@inria.fr> + + PR c++/60517 + * c-typeck.c (c_finish_return): Return 0 instead of the address of + a local variable. + 2014-07-30 Tom Tromey <tromey@redhat.com> * c-typeck.c (struct constructor_stack) <designator_depth>: New diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a938933..fe9440c 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9350,8 +9350,12 @@ c_finish_return (location_t loc, tree retval, tree origtype) warning_at (loc, OPT_Wreturn_local_addr, "function returns address of label"); else - warning_at (loc, OPT_Wreturn_local_addr, - "function returns address of local variable"); + { + warning_at (loc, OPT_Wreturn_local_addr, + "function returns address of local variable"); + tree zero = build_zero_cst (TREE_TYPE (res)); + t = build2 (COMPOUND_EXPR, TREE_TYPE (res), t, zero); + } } break; |