llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Clang should have a warning when classes do not follow rule of three

Open ZequanWu opened this issue 6 years ago • 2 comments

Bugzilla Link 46385
Version trunk
OS All
CC @dwblaikie,@zmodem,@zygoloid

Extended Description

Chrome folks suggest at here, https://bugs.chromium.org/p/chromium/issues/detail?id=979077.

It is good to have a warning that enforces the rule of three https://en.cppreference.com/w/cpp/language/rule_of_three. Whenever a class has only one or two of user-defined destructor, a user-defined copy constructor and a user-defined copy assignment operator, Clang warns at this class.

ZequanWu avatar Jun 18 '20 18:06 ZequanWu

There already exists a clang-tidy check for this, https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-special-member-functions.html

ZequanWu avatar Jun 26 '20 18:06 ZequanWu

You can get 2/3 of this with -Wdeprecated-copy-dtor (though it's on-use, rather than in the class itself). Beyond that I think it's more in the realm of clang-tidy than the clang compiler itself.

dwblaikie avatar Jun 18 '20 18:06 dwblaikie