hokein updated this revision to Diff 487382. hokein marked an inline comment as done. hokein added a comment.
update 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,19 @@ 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). + // Ignore them by traversing arguments instead of children. + for (auto *Arg : S->arguments()) + if (!TraverseStmt(Arg)) + return false; + return true; + } + bool VisitDeclRefExpr(DeclRefExpr *DRE) { report(DRE->getLocation(), DRE->getFoundDecl()); return true;
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,19 @@ 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). + // Ignore them by traversing arguments instead of children. + for (auto *Arg : S->arguments()) + if (!TraverseStmt(Arg)) + return false; + return true; + } + bool VisitDeclRefExpr(DeclRefExpr *DRE) { report(DRE->getLocation(), DRE->getFoundDecl()); return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits