[PATCH] D132713: [clang-tidy] Skip union-like classes in use-equals-default

Alexander Shaposhnikov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 13:58:22 PDT 2022


alexander-shaposhnikov added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp:220
 void UseEqualsDefaultCheck::registerMatchers(MatchFinder *Finder) {
-  // Skip unions since constructors with empty bodies behave differently
-  // in comparison with structs/classes.
+  // Skip union-like classes since constructors with empty bodies behave
+  // differently in comparison with structs/classes.
----------------
gribozavr2 wrote:
> 
I've come across "union-like" classes here: https://en.cppreference.com/w/cpp/language/union
but yeah, will rephrase the comment.


================
Comment at: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp:225
+      anyOf(isUnion(),
+            has(fieldDecl(isImplicit(), hasType(cxxRecordDecl(isUnion()))))));
 
----------------
gribozavr2 wrote:
> Why is "isImplicit" needed?
the intention for this patch was to skip classes containing anonymous unions
https://en.cppreference.com/w/cpp/language/union
In this case Clang's AST looks like this:
CXXRecordDecl - /* union */ FieldDecl (implicit) - IndirectFieldDecl - IndirectFieldDecl ...
For regular unions I haven't encountered issues yet (on a few large codebases)
(but yeah, might have to revisit it in the future).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132713/new/

https://reviews.llvm.org/D132713



More information about the cfe-commits mailing list