[PATCH] D108370: [clang-tidy] Fix wrong FixIt about union in cppcoreguidelines-pro-type-member-init

liushuai wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 19 06:31:59 PDT 2021


MTC added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp:49
+void forEachFieldWithFilter(const RecordDecl &Record, const T &Fields,
+                            bool &AnyMemberHasInitPerUnion, Func &&Fn) {
+  for (const FieldDecl *F : Fields) {
----------------
Can it be modified to the following form? Or further abstract `filter` into a parameter to make this function more general.


```
template <typename T, typename Func>
void forEachFieldWithFilter(const RecordDecl &Record, const T &Fields,
                            bool &AnyMemberHasInitPerUnion, Func &&Fn) {
  forEachField(Record, Fields, Fn);
  if (Record.isUnion() && AnyMemberHasInitPerUnion)
    break;
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108370



More information about the cfe-commits mailing list