Skip to content

Commit a426ffd

Browse files
authored
[include-cleaner] Add handling for new/delete expressions (llvm#104033)
1 parent 1db674b commit a426ffd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "clang/Basic/IdentifierTable.h"
2424
#include "clang/Basic/SourceLocation.h"
2525
#include "clang/Basic/Specifiers.h"
26-
#include "llvm/ADT/STLExtras.h"
2726
#include "llvm/ADT/STLFunctionalExtras.h"
2827
#include "llvm/ADT/SmallVector.h"
2928
#include "llvm/Support/Casting.h"
@@ -350,6 +349,15 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
350349
RefType::Implicit);
351350
return true;
352351
}
352+
353+
bool VisitCXXNewExpr(CXXNewExpr *E) {
354+
report(E->getExprLoc(), E->getOperatorNew());
355+
return true;
356+
}
357+
bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
358+
report(E->getExprLoc(), E->getOperatorDelete());
359+
return true;
360+
}
353361
};
354362

355363
} // namespace

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -555,5 +555,12 @@ TEST(WalkAST, FriendDecl) {
555555
testWalk("void $explicit^foo();", "struct Bar { friend void ^foo(); };");
556556
testWalk("struct $explicit^Foo {};", "struct Bar { friend struct ^Foo; };");
557557
}
558+
559+
TEST(WalkAST, OperatorNewDelete) {
560+
testWalk("void* $explicit^operator new(unsigned long, void*);",
561+
"struct Bar { void foo() { Bar b; ^new (&b) Bar; } };");
562+
testWalk("struct A { static void $explicit^operator delete(void*); };",
563+
"void foo() { A a; ^delete &a; }");
564+
}
558565
} // namespace
559566
} // namespace clang::include_cleaner

0 commit comments

Comments
 (0)