[clang-tools-extra] [clang-tidy] Fix false positive in readability-make-member-function-c… (PR #174286)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 15 21:50:59 PST 2026


================
@@ -154,6 +154,16 @@ class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
       // 1) has builtin type (a 'const int' cannot be modified),
       // 2) or it's a public member (the pointee of a public 'int * const' can
       // can be modified by any user of the class).
+
+      // Union members are never safe for pointer/reference types
+      // (all union members share memory).
+      if (const auto *Field = dyn_cast<FieldDecl>(Member->getMemberDecl());
+          Field->getParent()->isUnion()) {
----------------
zwuis wrote:

If `getMemberDecl()` always returns `FieldDecl`, use `cast`. If not, we should check if `Field` is null.

https://github.com/llvm/llvm-project/pull/174286


More information about the cfe-commits mailing list