[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
Tue Mar 12 11:51:04 PDT 2024


================
@@ -165,20 +165,20 @@ void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 
 void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
   auto MatchedDirectCallExpr = expr(
-      callExpr(
-          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)))))))))
+      callExpr(callee(functionDecl(
+                   // Don't match void overloads of checked functions.
+                   unless(returns(voidType())),
+                   // Don't match copy or move assignment operator.
+                   unless(cxxMethodDecl(isOperatorOverloading(
----------------
PiotrZSL wrote:

Just curios, what about operators outside class, like:
```
struct S {
  S(){};
  S(S const &);
  S(S &&);
};

  S &operator+=(S& s, S s2);

void test()
{
    S s;
    S s2;

    s += s2;

    operator+=(s, s2);
}
```

in AST those are functions, not methods:
```
-FunctionDecl <line:7:3, col:27> col:6 used operator+= 'S &(S &, S)'
| |-ParmVarDecl <col:17, col:20> col:20 s 'S &'
| `-ParmVarDecl <col:23, col:25> col:25 s2 'S':'S'
```

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


More information about the cfe-commits mailing list