This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc5fb7a79b58: [include-cleaner] Unify behaviour for static
& instance members (authored by kadircet).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D148552/new/
https://reviews.llvm.org/D148552
Files:
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -114,7 +114,7 @@
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, 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; };",
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -125,7 +125,13 @@
}
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;
}
Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===================================================================
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -114,7 +114,7 @@
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, 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; };",
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===================================================================
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -125,7 +125,13 @@
}
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;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits