This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] fix duplicate '{}' in cppcoreguidelines-pro-type-member-init
ClosedPublic

Authored by Sockke on Aug 6 2021, 6:18 AM.

Details

Summary

The overload of the constructor will repeatedly fix the member variables that need to be initialized.
Removed the duplicate '{}'.

struct A {
  A() {}
  A(int) {}
  int _var;  // int _var{}{};  <--  wrong fix
};

Diff Detail

Event Timeline

Sockke created this revision.Aug 6 2021, 6:18 AM
Sockke requested review of this revision.Aug 6 2021, 6:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 6 2021, 6:18 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
MTC added inline comments.Aug 7 2021, 6:59 PM
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
36

Btw, the parameter Record seems useless, could you clean it up in another patch?

439

I believe DenseSet::contains is more appropriate here.

453

FieldsToInit being empty implies AllFieldsToInit is empty. We have checked the emptiness of FieldsToInit.

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
210–211

Please update the comments.

MTC added inline comments.Aug 8 2021, 11:18 PM
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
453

never mind, what I said is wrong!

Sockke updated this revision to Diff 365159.Aug 9 2021, 4:54 AM

Format and add some description.

Sockke marked 2 inline comments as done.Aug 10 2021, 6:12 AM

Any thoughts?

Sockke marked an inline comment as done.Aug 11 2021, 8:57 AM

Any thoughts? : )

aaron.ballman added inline comments.Aug 11 2021, 9:07 AM
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
439

+1 to the suggestion to use contains().

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.h
79
aaron.ballman accepted this revision.Aug 12 2021, 4:29 AM

LGTM, thank you!

This revision is now accepted and ready to land.Aug 12 2021, 4:29 AM