Skip to content

Commit 74b538d

Browse files
authored
[include-cleaner] Turn new/delete usages to ambiguous references (#105844)
In practice most of these expressions just resolve to implicitly provided `operator new` and standard says it's not necessary to include `<new>` for that. Hence this is resulting in a lot of churn in cases where inclusion of `<new>` doesn't matter, and might even be undesired by the developer. By switching to an ambiguous reference we try to find a middle ground here, ensuring that we don't drop providers of `operator new` when the developer explicitly listed them in the includes, and chose to believe it's the implicitly provided `operator new` and don't insert an include in other cases.
1 parent 1f89cd4 commit 74b538d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
351351
}
352352

353353
bool VisitCXXNewExpr(CXXNewExpr *E) {
354-
report(E->getExprLoc(), E->getOperatorNew());
354+
report(E->getExprLoc(), E->getOperatorNew(), RefType::Ambiguous);
355355
return true;
356356
}
357357
bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
358-
report(E->getExprLoc(), E->getOperatorDelete());
358+
report(E->getExprLoc(), E->getOperatorDelete(), RefType::Ambiguous);
359359
return true;
360360
}
361361
};

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ TEST(WalkAST, FriendDecl) {
557557
}
558558

559559
TEST(WalkAST, OperatorNewDelete) {
560-
testWalk("void* $explicit^operator new(decltype(sizeof(int)), void*);",
560+
testWalk("void* $ambiguous^operator new(decltype(sizeof(int)), void*);",
561561
"struct Bar { void foo() { Bar b; ^new (&b) Bar; } };");
562-
testWalk("struct A { static void $explicit^operator delete(void*); };",
562+
testWalk("struct A { static void $ambiguous^operator delete(void*); };",
563563
"void foo() { A a; ^delete &a; }");
564564
}
565565
} // namespace

0 commit comments

Comments
 (0)