This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Ignore other members in a union if any member of it is initialized in cppcoreguidelines-pro-type-member-init
ClosedPublic

Authored by Sockke on Jun 8 2022, 5:03 AM.

Details

Summary

If a union member is initialized, the other members of the union are still suggested to be initialized in this check. This patch fixes this behavior.
Reference issue: https://github.com/llvm/llvm-project/issues/54748

Diff Detail

Event Timeline

Sockke created this revision.Jun 8 2022, 5:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2022, 5:03 AM
Sockke requested review of this revision.Jun 8 2022, 5:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2022, 5:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Sockke set the repository for this revision to rG LLVM Github Monorepo.Jun 8 2022, 5:03 AM
njames93 added inline comments.Jun 8 2022, 10:29 AM
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-member-init.cpp
558 ↗(On Diff #435106)

This line is redundant and likely to cause unintended test failures, same goes below.
If there was a warning on this line and no directive for it, the check script would fail due to that.

Sockke updated this revision to Diff 435409.Jun 8 2022, 8:01 PM
Sockke edited the summary of this revision. (Show Details)

Fix test file.

Sockke updated this revision to Diff 438295.Jun 20 2022, 1:54 AM

rebased.

LegalizeAdulthood requested changes to this revision.Jun 22 2022, 2:10 PM

Clang-Tidy tests and docs have moved to module subdirectories.

Please rebase this onto main:HEAD and:

  • fold your changes into the appropriate subdirs, stripping the module prefix from new files.
  • make the target check-clang-extra to validate your tests
  • make the target docs-clang-tools-html to validate any docs changes
This revision now requires changes to proceed.Jun 22 2022, 2:10 PM
Sockke updated this revision to Diff 440517.Jun 28 2022, 1:13 AM

rebased.

LegalizeAdulthood requested changes to this revision.Jun 29 2022, 8:27 AM

Please add a summary of the fix to the release notes for this check.

This revision now requires changes to proceed.Jun 29 2022, 8:27 AM
Sockke updated this revision to Diff 441241.Jun 29 2022, 8:22 PM

Added release notes.

Sockke added a comment.Jul 8 2022, 4:13 AM

Friendly ping.

Friendly ping.

Can you add test cases where there is a struct with an anonymous union and another field that does need an initializer, just to verify warning and fixit behaviour.

struct S3 {
  S3() {}
  int A;
  union {
    int B;
    int C = 0; // Possibly a case where this is initialized in the member init list.
  };
};
clang-tools-extra/docs/ReleaseNotes.rst
137–139

Can't think of the nicest way to say this, but I think this is a little more understandable.

Sockke updated this revision to Diff 445792.Jul 19 2022, 5:50 AM

Added test cases where there is a struct with an anonymous union and another field that does need an initializer.

Friendly ping.

njames93 accepted this revision.Jul 28 2022, 3:16 AM

LGTM, You'd need to rebase before landing as the release notes have been reset for the 15 release branching.

Sockke updated this revision to Diff 449188.Aug 1 2022, 11:15 PM

Rebased.

thieta added a subscriber: thieta.Aug 15 2022, 6:55 AM

Hi @Sockke - this seems to be ready to land. Is there something holding it back? We ran into the same issue recently.

Hi, @LegalizeAdulthood, are you okay with the way this has progressed?

Sockke updated this revision to Diff 455516.Aug 25 2022, 2:38 AM

Rebased.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 25 2022, 3:49 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.

This patch has been around for a long time, I have added the release notes. There are users waiting for this fix and I committed it myself first.
@LegalizeAdulthood I'm looking forward to your follow-up reply.