Skip to content

Commit

Permalink
[include-cleaner] Treat member operator calls as implicit
Browse files Browse the repository at this point in the history
26ff268 treated member operator calls
as explicit, while trying to treat them the same way as regular member
expressions, which should've been implicit.
  • Loading branch information
kadircet committed Apr 3, 2023
1 parent 367db8b commit f323e7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions clang-tools-extra/include-cleaner/lib/WalkAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();");
}

Expand Down

0 comments on commit f323e7f

Please sign in to comment.