[clang-tools-extra] f323e7f - [include-cleaner] Treat member operator calls as implicit
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 3 07:28:22 PDT 2023
Author: Kadir Cetinkaya
Date: 2023-04-03T16:27:23+02:00
New Revision: f323e7f3ca760be786d2584c926edade34c3fbde
URL: https://github.com/llvm/llvm-project/commit/f323e7f3ca760be786d2584c926edade34c3fbde
DIFF: https://github.com/llvm/llvm-project/commit/f323e7f3ca760be786d2584c926edade34c3fbde.diff
LOG: [include-cleaner] Treat member operator calls as implicit
26ff268b80c589fd9f71c1c214af77cd972642ca treated member operator calls
as explicit, while trying to treat them the same way as regular member
expressions, which should've been implicit.
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 8a1dd77176cd..ab1476ea0997 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -95,14 +95,15 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
// to them doesn't count as uses (generally the type should provide them, so
// ignore them).
// Unless we're using an operator defined as a member, in such cases treat
- // this as a regular reference.
+ // these as regular member references.
bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *S) {
if (!WalkUpFromCXXOperatorCallExpr(S))
return false;
if (auto *CD = S->getCalleeDecl()) {
if (llvm::isa<CXXMethodDecl>(CD)) {
// Treat this as a regular member reference.
- report(S->getOperatorLoc(), getMemberProvider(S->getArg(0)->getType()));
+ report(S->getOperatorLoc(), getMemberProvider(S->getArg(0)->getType()),
+ RefType::Implicit);
} else {
report(S->getOperatorLoc(), llvm::dyn_cast<NamedDecl>(CD),
RefType::Implicit);
diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index fceec670076c..ac2085d82c1d 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -296,12 +296,12 @@ TEST(WalkAST, Operator) {
testWalk(
"struct string { friend int $implicit^operator+(string, string); }; ",
"int k = string() ^+ string();");
- // Unless they're members, we treat them as regular member expr calls.
- testWalk("struct $explicit^string {int operator+(string); }; ",
+ // Treat member operators as regular member expr calls.
+ testWalk("struct $implicit^string {int operator+(string); }; ",
"int k = string() ^+ string();");
// Make sure usage is attributed to the alias.
testWalk(
- "struct string {int operator+(string); }; using $explicit^foo = string;",
+ "struct string {int operator+(string); }; using $implicit^foo = string;",
"int k = foo() ^+ string();");
}
More information about the cfe-commits
mailing list