This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/85856] New: -Weffc++ can't see implicitly deleted constructor


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

            Bug ID: 85856
           Summary: -Weffc++ can't see implicitly deleted constructor
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msharov at users dot sourceforge.net
  Target Milestone: ---

#include <stdio.h>

struct A {
    A (void) {}
    virtual ~A (void) {}
    A (const A&) = delete;
    void operator= (const A&) = delete;
};

struct B : public A {
    B (const char* p) :A(),_p(p) {}
    const char* _p;
};

int main (void)
{
    B b ("hello");
    puts (b._p);
    return 0;
}

When compiling with -Weffc++ enabled, generates:

t.cc:10:8: warning: ‘struct B’ has pointer data members [-Weffc++]
 struct B : public A {
        ^
t.cc:10:8: warning:   but does not override ‘B(const B&)’ [-Weffc++]
t.cc:10:8: warning:   or ‘operator=(const B&)’ [-Weffc++]

B already has an implicitly deleted copy constructor and operator= because A
implements them deleted. The compiler will correctly give a warning about it on
B b2=b, for example.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]