https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63203

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
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.

Reply via email to