[clang-tools-extra] a426ffd - [include-cleaner] Add handling for new/delete expressions (#104033)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 16 04:18:02 PDT 2024


Author: kadir çetinkaya
Date: 2024-08-16T13:17:58+02:00
New Revision: a426ffdee1ca7814f2684b6104c48f5669815aad

URL: https://github.com/llvm/llvm-project/commit/a426ffdee1ca7814f2684b6104c48f5669815aad
DIFF: https://github.com/llvm/llvm-project/commit/a426ffdee1ca7814f2684b6104c48f5669815aad.diff

LOG: [include-cleaner] Add handling for new/delete expressions (#104033)

Added: 
    

Modified: 
    clang-tools-extra/include-cleaner/lib/WalkAST.cpp
    clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index b15d428326ac12..a5ac3760a3be2a 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -23,7 +23,6 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
@@ -350,6 +349,15 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
            RefType::Implicit);
     return true;
   }
+
+  bool VisitCXXNewExpr(CXXNewExpr *E) {
+    report(E->getExprLoc(), E->getOperatorNew());
+    return true;
+  }
+  bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+    report(E->getExprLoc(), E->getOperatorDelete());
+    return true;
+  }
 };
 
 } // namespace

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 282abce3246ca3..79371f5978fc33 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -555,5 +555,12 @@ TEST(WalkAST, FriendDecl) {
   testWalk("void $explicit^foo();", "struct Bar { friend void ^foo(); };");
   testWalk("struct $explicit^Foo {};", "struct Bar { friend struct ^Foo; };");
 }
+
+TEST(WalkAST, OperatorNewDelete) {
+  testWalk("void* $explicit^operator new(unsigned long, void*);",
+           "struct Bar { void foo() { Bar b; ^new (&b) Bar; } };");
+  testWalk("struct A { static void $explicit^operator delete(void*); };",
+           "void foo() { A a; ^delete &a; }");
+}
 } // namespace
 } // namespace clang::include_cleaner


        


More information about the cfe-commits mailing list