[PATCH] D108370: [clang-tidy] Fix wrong FixIt about union in cppcoreguidelines-pro-type-member-init
gehry via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 20 05:54:54 PDT 2021
Sockke added a comment.
Any thoughts? : )
================
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) {
----------------
MTC wrote:
> 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;
> }
> ```
> 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;
> }
> ```
This does not seem to work, because the "AnyMemberHasInitPerUnion" needs to be passed along the call stack.
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