Skip to content

Commit

Permalink
[include-cleaner] Unify behaviour for static & instance members
Browse files Browse the repository at this point in the history
Fixes #62185

Differential Revision: https://reviews.llvm.org/D148552
  • Loading branch information
kadircet committed Apr 18, 2023
1 parent d5b6312 commit cc5fb7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion clang-tools-extra/include-cleaner/lib/WalkAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
}

bool VisitDeclRefExpr(DeclRefExpr *DRE) {
report(DRE->getLocation(), DRE->getFoundDecl());
// Static class members are handled here, as they don't produce MemberExprs.
if (DRE->getFoundDecl()->isCXXClassMember()) {
if (auto *Qual = DRE->getQualifier())
report(DRE->getLocation(), Qual->getAsRecordDecl(), RefType::Implicit);
} else {
report(DRE->getLocation(), DRE->getFoundDecl());
}
return true;
}

Expand Down
9 changes: 8 additions & 1 deletion clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ TEST(WalkAST, DeclRef) {
testWalk("int $explicit^x;", "int y = ^x;");
testWalk("int $explicit^foo();", "int y = ^foo();");
testWalk("namespace ns { int $explicit^x; }", "int y = ns::^x;");
testWalk("struct S { static int $explicit^x; };", "int y = S::^x;");
testWalk("struct $implicit^S { static int x; };", "int y = S::^x;");
// Canonical declaration only.
testWalk("extern int $explicit^x; int x;", "int y = ^x;");
// Return type of `foo` isn't used.
Expand Down Expand Up @@ -342,6 +342,13 @@ TEST(WalkAST, TemplateNames) {
}

TEST(WalkAST, MemberExprs) {
testWalk("struct $implicit^S { static int f; };", "void foo() { S::^f; }");
testWalk("struct B { static int f; }; struct $implicit^S : B {};",
"void foo() { S::^f; }");
testWalk("struct B { static void f(); }; struct $implicit^S : B {};",
"void foo() { S::^f; }");
testWalk("struct B { static void f(); }; ",
"struct S : B { void foo() { ^f(); } };");
testWalk("struct $implicit^S { void foo(); };", "void foo() { S{}.^foo(); }");
testWalk(
"struct S { void foo(); }; struct $implicit^X : S { using S::foo; };",
Expand Down

0 comments on commit cc5fb7a

Please sign in to comment.