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

            Bug ID: 64667
           Summary: -Winit-self ignored for reference fields
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gnu at drewnoakes dot com

GCC doesn't warn when initialising a field of reference type from itself in a
copy constructor.

Consider:

    class A
    {
    public:
       A(const A&) : a(a), b(b), c(c) {}
    private:
       int a;
       int* b;
       int& c;
    };

Warnings are offered for field a and b, but not c.

    $ g++ -std=c++11 -Winit-self test.cc
    test.cc: In copy constructor ‘A::A(const A&)’:
    test.cc:4:8: warning: ‘A::a’ is initialized with itself [-Winit-self]
            A(const A&) : a(a), b(b), c(c) {}
            ^
    test.cc:4:8: warning: ‘A::b’ is initialized with itself [-Winit-self]

Testing this with clang does trigger a warning, though with a different message
for c than a and b.

Reply via email to