This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix cppcoreguidelines-pro-type-member-init false negatives
ClosedPublic

Authored by malcolm.parsons on Sep 27 2016, 8:13 AM.

Details

Summary

Handle classes with default constructors that are defaulted or are not
present in the AST.
Classes with virtual methods or virtual bases are not trivially
default constructible, so their members and bases need to be initialized.

Event Timeline

malcolm.parsons retitled this revision from to [clang-tidy] Fix cppcoreguidelines-pro-type-member-init false negatives.
malcolm.parsons updated this object.
malcolm.parsons added subscribers: cfe-commits, mgehre.
aaron.ballman added inline comments.Oct 3 2016, 1:25 PM
clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
307

Please add an explanatory string literal to the assert (that way, if it triggers, some more information is immediately available).

372–374

Should also update the comment.

test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
401

Can you also add a test like:

template <typename T>
struct S {
  T Val;
  virtual ~S() = default;
};

template struct S<int>;

Don't match template instantiations.
Add assert message.
Update macro comment.
Add tests for templates and macros.

aaron.ballman edited edge metadata.Oct 4 2016, 6:34 AM

Generally looks good to me, sorry I missed these tiny nits last time around.

clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
49

Since this is not allowed to be a null pointer, would it make more sense to use a reference instead (same below)?

test/clang-tidy/cppcoreguidelines-pro-type-member-init.cpp
409

Sorry, I missed one bit to my test (my fault), can you also add int F; to ensure that it still triggers the diagnostic?

malcolm.parsons edited edge metadata.

Pass records by reference.
Change test to trigger diagnostic for non-template type

aaron.ballman accepted this revision.Oct 4 2016, 7:15 AM
aaron.ballman edited edge metadata.

LGTM, thank you!

This revision is now accepted and ready to land.Oct 4 2016, 7:15 AM

LGTM, thank you!

I don't have commit access, so please commit this for me.
Thanks.

aaron.ballman closed this revision.Oct 4 2016, 7:57 AM

I've commit in r283224.