================ @@ -0,0 +1,61 @@ +//===--- 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(hasType(hasCanonicalType(referenceType( + pointee(equalsBoundNode("type")))))) + .bind("member"); + auto AssignLHS = memberExpr( + hasObjectExpression(ignoringParenCasts(cxxThisExpr())), member(RefField)); + auto DerefOperand = expr(ignoringParenCasts( + declRefExpr(to(parmVarDecl(equalsBoundNode("parm")))))); + auto AssignRHS = expr(ignoringParenCasts( + unaryOperator(hasOperatorName("*"), hasUnaryOperand(DerefOperand)))); + + auto BinaryOpAssign = binaryOperator(hasOperatorName("="), hasLHS(AssignLHS), + hasRHS(AssignRHS)); + auto CXXOperatorCallAssign = cxxOperatorCallExpr( + hasOverloadedOperatorName("="), hasLHS(AssignLHS), hasRHS(AssignRHS)); + + auto SetBody = + compoundStmt(statementCountIs(1), + anyOf(has(BinaryOpAssign), has(CXXOperatorCallAssign))); + auto BadSetFunction = + cxxMethodDecl( + parameterCountIs(1), isPublic(), ---------------- vbvictor wrote:
```suggestion parameterCountIs(1), ``` Is `isPublic()` needed here? I thought we would remove any visibility specifiers. Consider this example https://godbolt.org/z/v35dG5rax, I can call a protected method via inheritance, so protected methods can also be called as public. https://github.com/llvm/llvm-project/pull/132242 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits