diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2023-04-17 20:25:25 +0200 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2023-04-18 10:01:31 +0200 |
commit | cc5fb7a79b58d7e6509b74e1935850e3307bbdc7 (patch) | |
tree | f20049b332aa0378a3d6ad9067ce0b60272cb755 /clang-tools-extra/include-cleaner | |
parent | d5b631240aac61ff4dca064bc495fbadb4bb2453 (diff) | |
download | llvm-cc5fb7a79b58d7e6509b74e1935850e3307bbdc7.tar.gz |
[include-cleaner] Unify behaviour for static & instance members
Fixes https://github.com/llvm/llvm-project/issues/62185
Differential Revision: https://reviews.llvm.org/D148552
Diffstat (limited to 'clang-tools-extra/include-cleaner')
-rw-r--r-- | clang-tools-extra/include-cleaner/lib/WalkAST.cpp | 8 | ||||
-rw-r--r-- | clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp index e977bcbb402f..4ea7bceeb96e 100644 --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -125,7 +125,13 @@ public: } 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; } diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp index 2060ffe3bb56..ffe8bbffc371 100644 --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -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. @@ -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; };", |