[clang-tools-extra] [clang-tidy] Add check bugprone-misleading-setter-of-reference (PR #132242)
DonĂ¡t Nagy via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 07:42:12 PDT 2025
================
@@ -0,0 +1,58 @@
+//===--- MisleadingSetterOfReferenceCheck.cpp - clang-tidy-----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MisleadingSetterOfReferenceCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void MisleadingSetterOfReferenceCheck::registerMatchers(MatchFinder *Finder) {
+ auto RefField =
+ fieldDecl(unless(isPublic()),
----------------
NagyDonat wrote:
I agree that those cases (where a public reference member has a setter function with misleading type) are "twice buggy" (because public members should not have a setter function in any case), but this means that they are very unlikely to appear in the analyzed code, so we shouldn't complicate the behavior of this checker with extra code for it.
As we discussed on the meeting, please remove the `unless(isPublic())` condition.
https://github.com/llvm/llvm-project/pull/132242
More information about the cfe-commits
mailing list