[PATCH] D140551: [include-cleaner] Don't count references to operators as uses
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 9 05:03:03 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG499bf67208d9: [include-cleaner] Don't count references to operators as uses (authored by hokein).
Changed prior to commit:
https://reviews.llvm.org/D140551?vs=487382&id=487388#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140551/new/
https://reviews.llvm.org/D140551
Files:
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -245,6 +245,16 @@
testWalk("struct S { $implicit^S(int); };", "S t = ^42;");
}
+TEST(WalkAST, Operator) {
+ // References to operators are not counted as uses.
+ testWalk("struct string {}; int operator+(string, string);",
+ "int k = string() ^+ string();");
+ testWalk("struct string {int operator+(string); }; ",
+ "int k = string() ^+ string();");
+ testWalk("struct string { friend int operator+(string, string); }; ",
+ "int k = string() ^+ string();");
+}
+
TEST(WalkAST, Functions) {
// Definition uses declaration, not the other way around.
testWalk("void $explicit^foo();", "void ^foo() {}");
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -66,6 +66,20 @@
public:
ASTWalker(DeclCallback Callback) : Callback(Callback) {}
+ bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
+ if (!WalkUpFromCXXOperatorCallExpr(S))
+ return false;
+
+ // Operators are always ADL extension points, by design references to them
+ // doesn't count as uses (generally the type should provide them).
+ // Don't traverse the callee.
+
+ for (auto *Arg : S->arguments())
+ if (!TraverseStmt(Arg))
+ return false;
+ return true;
+ }
+
bool VisitDeclRefExpr(DeclRefExpr *DRE) {
report(DRE->getLocation(), DRE->getFoundDecl());
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140551.487388.patch
Type: text/x-patch
Size: 1790 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230109/97a3cd3a/attachment.bin>
More information about the cfe-commits
mailing list