From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23757 invoked by alias); 8 Sep 2014 10:16:51 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 23666 invoked by uid 48); 8 Sep 2014 10:16:36 -0000 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/63203] Self-initialization of reference not diagnosed if it occurs within a loop Date: Mon, 08 Sep 2014 10:16:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-09/txt/msg01253.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63203 --- Comment #2 from Jonathan Wakely --- I tried something like this: --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6101,6 +6101,12 @@ initialize_local_var (tree decl, tree init) -Wno-init-self works (c++/34772). */ gcc_assert (TREE_OPERAND (init, 0) == decl); DECL_INITIAL (decl) = TREE_OPERAND (init, 1); + + if (warn_init_self && TREE_CODE (type) == REFERENCE_TYPE + && TREE_OPERAND (init, 1) == decl) + warning_at (DECL_SOURCE_LOCATION (decl), + OPT_Winit_self, + "Reference %qD is initialized with itself", decl); } else { but the TREE_OPERAND (init, 1) == decl condition is false and I'm not sure how to fix it.