[Bug c++/88050] Add a warning for breaking the "Rule of Three"

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Nov 16 11:35:00 GMT 2018


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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Your example doesn't even compile, the destructor is private.

GCC now has -Wdeprecated-copy which warns for this fixed example:

struct Type
{
    ~Type()
    {}
};

int main()
{
  Type t;
  Type tt = t;
  t = tt;
}

r.cc: In function 'int main()':
r.cc:10:13: warning: implicitly-declared 'constexpr Type::Type(const Type&)' is
deprecated [-Wdeprecated-copy]
   10 |   Type tt = t;
      |             ^
r.cc:3:5: note: because 'Type' has user-provided 'Type::~Type()'
    3 |     ~Type()
      |     ^
r.cc:11:7: warning: implicitly-declared 'constexpr Type& Type::operator=(const
Type&)' is deprecated [-Wdeprecated-copy]
   11 |   t = tt;
      |       ^~
r.cc:3:5: note: because 'Type' has user-provided 'Type::~Type()'
    3 |     ~Type()
      |     ^


These warnings are given unless the copy constructor and copy assignment
operator are user-declared, which is pretty close to what you're requesting.
The warnings are only issued if the implicitly-declared special member
functions are actually used (because if they're never used then it doesn't
matter if they're defined or not).

I think this bug can be closed.


More information about the Gcc-bugs mailing list