Page MenuHomePhabricator

Add modernize-use-default check to clang-tidy.
ClosedPublic

Authored by angelgarcia on Oct 19 2015, 8:10 AM.

Details

Summary

Add a check that replaces empty bodies of special member functions with '= default;'.
For now, it is only implemented for the default constructor and the destructor, which are the easier cases.
The copy-constructor and the copy-assignment operator cases will be implemented later.

I applied this check to the llvm code base and found 627 warnings (385 in llvm, 9 in compiler-rt, 220 in clang and 13 in clang-tools-extra).
Applying the fixes didn't break any build or test, it only caused a -Wpedantic warning in lib/Target/Mips/MipsOptionRecord.h:33 becaused it replaced
virtual ~MipsOptionRecord(){}; to virtual ~MipsOptionRecord()= default;;

Diff Detail

Event Timeline

angelgarcia retitled this revision from to Add modernize-use-default check to clang-tidy..
angelgarcia updated this object.
angelgarcia added a reviewer: klimek.
angelgarcia added subscribers: cfe-commits, alexfh.

Will be good idea to add handling of cases where default constructor is empty and only call base class(es) default constructor/members default constructors (see http://en.cppreference.com/w/cpp/language/default_constructor).

In test check should suggest to use default for N() : H() {}.

Of course, if it will be easy to implement. Otherwise, such cases may be left for future development.

This looks like a good check -- thanks for adding it! Just one small nit for you.

clang-tidy/modernize/UseDefaultCheck.cpp
20

I don't see where this is used outside of UseDefaultCheck.cpp. Can we make it static?

Global variable -> static, and a few other additions.

Will be good idea to add handling of cases where default constructor is empty and only call base class(es) default constructor/members default constructors

I agree, but checking all members and base classes is the main difficulty of the copy-constructor/copy-assignment operator. When I implement those I will probably update this.

klimek accepted this revision.Oct 20 2015, 5:23 AM
klimek edited edge metadata.

LG. Yay!

clang-tidy/modernize/UseDefaultCheck.cpp
60–61

Delete the fixme. There already is an extra semicolon in the first case.

This revision is now accepted and ready to land.Oct 20 2015, 5:23 AM
angelgarcia edited edge metadata.

Remove the fixme.

angelgarcia closed this revision.Oct 21 2015, 6:00 AM