================
@@ -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) {
+  if (Node.capture_size() != 0)
+    return false;
+  const CXXMethodDecl *CallOp = Node.getCallOperator();
+  if (!CallOp || CallOp->getNumParams() != 1)
+    return false;
+  const ParmVarDecl *Param = CallOp->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;
+}
+
+void UseSharedPtrArrayCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+      cxxConstructExpr(
+          unless(isInTemplateInstantiation()),
----------------
zwuis wrote:

Set the traversal kind of this check to `TK_IgnoreUnlessSpelledInSource` 
instead.

https://github.com/llvm/llvm-project/pull/199458
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to