diff options
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r-- | gcc/cp/decl.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 225d408..4ce4645 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6132,13 +6132,23 @@ initialize_local_var (tree decl, tree init) /* Perform the initialization. */ if (init) { - if (TREE_CODE (init) == INIT_EXPR - && !TREE_SIDE_EFFECTS (TREE_OPERAND (init, 1))) + tree rinit = (TREE_CODE (init) == INIT_EXPR + ? TREE_OPERAND (init, 1) : NULL_TREE); + if (rinit && !TREE_SIDE_EFFECTS (rinit)) { /* Stick simple initializers in DECL_INITIAL so that -Wno-init-self works (c++/34772). */ gcc_assert (TREE_OPERAND (init, 0) == decl); - DECL_INITIAL (decl) = TREE_OPERAND (init, 1); + DECL_INITIAL (decl) = rinit; + + if (warn_init_self && TREE_CODE (type) == REFERENCE_TYPE) + { + STRIP_NOPS (rinit); + if (rinit == decl) + warning_at (DECL_SOURCE_LOCATION (decl), + OPT_Winit_self, + "reference %qD is initialized with itself", decl); + } } else { |