================
@@ -0,0 +1,378 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "UseSharedPtrArrayCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/ExprCXX.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+AST_MATCHER(FunctionDecl, funcHasSingleArrayDeleteBody) {
+ if (Node.getNumParams() != 1 || !Node.hasBody())
+ return false;
+ const ParmVarDecl *Param = Node.getParamDecl(0);
+ const auto *CS = dyn_cast<CompoundStmt>(Node.getBody());
+ if (!CS || CS->size() != 1)
+ return false;
+ const auto *E = dyn_cast<Expr>(CS->body_front());
+ if (!E)
+ return false;
+ const auto *DE = dyn_cast<CXXDeleteExpr>(E->IgnoreParenImpCasts());
+ if (!DE || !DE->isArrayForm())
+ return false;
+ const auto *DRE =
+ dyn_cast<DeclRefExpr>(DE->getArgument()->IgnoreParenImpCasts());
+ return DRE && DRE->getDecl() == Param;
+}
+
+AST_MATCHER(LambdaExpr, lambdaHasSingleArrayDeleteBody) {
----------------
zwuis wrote:
Most of the body is duplicate of `funcHasSingleArrayDeleteBody`.
```cpp
lambdaExpr(
someNameLikeNoCapture(), // #1
someNameLikeGetTheFunctionDecl( // #2
funcHasSingleArrayDeleteBody()
)
)
```
We can add `#1` and `#2` two matchers and write matchers above to deduplicate
code.
https://github.com/llvm/llvm-project/pull/199458
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits