[clang-tools-extra] [clang-tidy]bugprone-unused-return-value ignore `++` and `--` operator overloading (PR #84922)
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 13 10:26:40 PDT 2024
================
@@ -169,16 +180,14 @@ void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
callee(functionDecl(
// Don't match void overloads of checked functions.
unless(returns(voidType())),
- // Don't match copy or move assignment operator.
- unless(cxxMethodDecl(isOperatorOverloading(
- {OO_Equal, OO_PlusEqual, OO_MinusEqual, OO_StarEqual,
- OO_SlashEqual, OO_PercentEqual, OO_CaretEqual, OO_AmpEqual,
- OO_PipeEqual, OO_LessLessEqual, OO_GreaterGreaterEqual}))),
anyOf(
isInstantiatedFrom(
matchers::matchesAnyListedName(CheckedFunctions)),
returns(hasCanonicalType(hasDeclaration(namedDecl(
- matchers::matchesAnyListedName(CheckedReturnTypes)))))))))
+ matchers::matchesAnyListedName(CheckedReturnTypes)))))))),
+ // Don't match copy or move assignment operator.
+ unless(cxxOperatorCallExpr(isAssignmentOverloadedOperatorCall())),
+ unless(callee(cxxMethodDecl(isAssignmentOverloadedOperatorMethod()))))
----------------
PiotrZSL wrote:
try changing this code in a way so callee woudn't be checked if cxxOperatorCallExpr were already checked.
you could do it like this:
```
anyOf(cxxOperatorCallExpr(unless(isAssignmentOverloadedOperatorCall()),
unless(callee(functionDecl(isAssignmentOverloadedOperatorFunction()))))
```
You may also consider moving this before all those matchers::matchesAnyListedName, so names woudn't be checked for operators at all.
https://github.com/llvm/llvm-project/pull/84922
More information about the cfe-commits
mailing list