This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Fix handling of UseAssignment option in cppcoreguidelines-prefer-member-initializer
ClosedPublic

Authored by PiotrZSL on Apr 10 2023, 4:23 AM.

Details

Summary

From now on check will use value from cppcoreguidelines-prefer-member-initializer
and fallback to modernize-use-default-member-init.UseAssignment if not specified.

Fixes: #55616.

Diff Detail

Event Timeline

PiotrZSL created this revision.Apr 10 2023, 4:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 4:23 AM
PiotrZSL requested review of this revision.Apr 10 2023, 4:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 10 2023, 4:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
carlosgalvezp added inline comments.Apr 10 2023, 4:47 AM
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
134

This is very strange, feels like it's done to ensure the checks are in sync but IMO it creates more harm than good and makes the check harder to maintain. The checks are independent anyway (not aliases), so I believe it makes sense to keep being independent also in the options.

There are similar checks (e.g. magic numbers) where the user needs to either only enable one of the checks, or enter the same configuration settings twice.

I would vote for just treating this like an independent argument like all other checks, to avoid bugs like these.

PiotrZSL added inline comments.Apr 10 2023, 5:19 AM
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
134

So remove dependency on modernize-use-default-member-init completly, or just on modernize-use-default-member-init options ?

carlosgalvezp accepted this revision.Apr 16 2023, 2:25 AM
carlosgalvezp added a subscriber: aaron.ballman.
carlosgalvezp added inline comments.
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
134

I had a look at the original patch:

https://reviews.llvm.org/D71199

There's quite some discussion about the topic, and reviewers like @aaron.ballman weren't very happy about introducing this coupling. Seems like the problem is non-trivial so I vote for leaving your patch as is, which fixes a Github ticket and brings value, and think about completely removing the dependency to modernize-use-default-member-init on a separate patch.

This revision is now accepted and ready to land.Apr 16 2023, 2:25 AM