[Bug c++/68208] g++ doesn't warn against reference self-initialization

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Nov 11 19:42:00 GMT 2015


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |msebor at gcc dot gnu.org
         Resolution|---                         |DUPLICATE

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
This is fixed on trunk, apparently via bug 64667.

Unfortunately, the warning in the reference and pointer cases is missing a
caret (see below), and in the member case points to the constructor rather than
to the member initializer.  The following patch fixes the location information.
 I'll submit it shortly.

index 2e11acb..055e9d9 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -638,7 +638,7 @@ perform_member_init (tree member, tree init)
        val = TREE_OPERAND (val, 0);
       if (TREE_CODE (val) == COMPONENT_REF && TREE_OPERAND (val, 1) == member
          && TREE_OPERAND (val, 0) == current_class_ref)
-       warning_at (DECL_SOURCE_LOCATION (current_function_decl),
+       warning_at (EXPR_LOC_OR_LOC (val, input_location),
                    OPT_Winit_self, "%qD is initialized with itself",
                    member);
     }


struct S {
    int m;
    int &r;
    int *p;
    S ():
    m (m),
    r (r),
    p (p)
    { }
};
u.cpp: In constructor ‘S::S()’:
u.cpp:5:5: warning: ‘S::m’ is initialized with itself [-Winit-self]
     S ():
     ^

u.cpp:5:5: warning: ‘S::r’ is initialized with itself [-Winit-self]
u.cpp:5:5: warning: ‘S::p’ is initialized with itself [-Winit-self]

*** This bug has been marked as a duplicate of bug 64667 ***


More information about the Gcc-bugs mailing list