aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-11-13 00:09:36 -0500
committerJason Merrill <jason@gcc.gnu.org>2011-11-13 00:09:36 -0500
commit2c6f792709071cd3492a10b79924674924f7fb1c (patch)
treed4bb198a43ba892c06b25855372885a1f92e3520 /gcc/cp/call.c
parentafe5cf219076d5f529ce767563aa36ea07970356 (diff)
downloadgcc-2c6f792709071cd3492a10b79924674924f7fb1c.zip
gcc-2c6f792709071cd3492a10b79924674924f7fb1c.tar.gz
gcc-2c6f792709071cd3492a10b79924674924f7fb1c.tar.bz2
re PR c++/986 (g++ misses warning for reference on temporary that invokes undefined behaviour)
PR c++/986 * call.c (set_up_extended_ref_temp): Warn about references bound to non-static reference members. * init.c (perform_member_init): Pass in the member. From-SVN: r181334
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index e81950c..ab06542 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -8607,6 +8607,14 @@ set_up_extended_ref_temp (tree decl, tree expr, VEC(tree,gc) **cleanups,
if (TREE_CODE (expr) != TARGET_EXPR)
expr = get_target_expr (expr);
+ if (TREE_CODE (decl) == FIELD_DECL
+ && extra_warnings && !TREE_NO_WARNING (decl))
+ {
+ warning (OPT_Wextra, "a temporary bound to %qD only persists "
+ "until the constructor exits", decl);
+ TREE_NO_WARNING (decl) = true;
+ }
+
/* Recursively extend temps in this initializer. */
TARGET_EXPR_INITIAL (expr)
= extend_ref_init_temps (decl, TARGET_EXPR_INITIAL (expr), cleanups);