[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
Tue Mar 25 06:14:49 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:
Is the `unless(isPublic())` condition necessary here?
At first I wanted to suggest that you should refer to it in the documentation (it's currently undocumented), but as I thought about that I think that it is a minor embellishment which is only loosely related to the core goals of the checker and just increases the complexity of the (already complex) matchers without providing real benefits.
(However, I can also accept keeping it if you think that it's important. In that case please refer to it in the docs.)
https://github.com/llvm/llvm-project/pull/132242
More information about the cfe-commits
mailing list