diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2023-04-03 16:26:06 +0200 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2023-04-03 16:27:23 +0200 |
commit | f323e7f3ca760be786d2584c926edade34c3fbde (patch) | |
tree | c6a2976bf1e2e0ed526357ecc46f63d2ea49752e /clang-tools-extra/include-cleaner | |
parent | 367db8bf6af51d3961b9efd1015fdb8a2d7686da (diff) | |
download | llvm-f323e7f3ca760be786d2584c926edade34c3fbde.tar.gz |
[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.
Diffstat (limited to 'clang-tools-extra/include-cleaner')
-rw-r--r-- | clang-tools-extra/include-cleaner/lib/WalkAST.cpp | 5 | ||||
-rw-r--r-- | clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp | 6 |
2 files changed, 6 insertions, 5 deletions
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 @@ public: // 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();"); } |