Bug 85856 - -Weffc++ can't see implicitly deleted constructor
Summary: -Weffc++ can't see implicitly deleted constructor
Status: RESOLVED DUPLICATE of bug 22406
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Weffc++
  Show dependency treegraph
 
Reported: 2018-05-21 15:00 UTC by Mike Sharov
Modified: 2018-05-21 17:03 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Sharov 2018-05-21 15:00:31 UTC
#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.
Comment 1 Jonathan Wakely 2018-05-21 17:03:23 UTC
There are loads of problems with -Weffc++, all related to the fact they are outdated rules based on the first edition of a book based on C++98.

This seems like a dup of PR 22406

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