[clang-tools-extra] [include-cleaner] Report refs for enum constants used through namespace aliases (PR #106706)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 30 03:28:57 PDT 2024


https://github.com/kadircet created https://github.com/llvm/llvm-project/pull/106706

None

>From 82ac332a3b94f6f753b706077b13f405ff776882 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya <kadircet at google.com>
Date: Fri, 30 Aug 2024 12:28:02 +0200
Subject: [PATCH] [include-cleaner] Report refs for enum constants used through
 namespace aliases

---
 clang-tools-extra/include-cleaner/lib/WalkAST.cpp           | 3 ++-
 clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index f7a2ebd5260681..9663c9916740eb 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -147,7 +147,8 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
     // If it's an enum constant, it must be due to prior decl. Report references
     // to it when qualifier isn't a type.
     if (llvm::isa<EnumConstantDecl>(FD)) {
-      if (!DRE->getQualifier() || DRE->getQualifier()->getAsNamespace())
+      if (!DRE->getQualifier() || DRE->getQualifier()->getAsNamespace() ||
+          DRE->getQualifier()->getAsNamespaceAlias())
         report(DRE->getLocation(), FD);
     }
     return true;
diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 9286758cab081c..9ae9f9a5ddb829 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -534,6 +534,8 @@ TEST(WalkAST, Enums) {
   testWalk(R"(namespace ns { enum E { A = 42 }; }
               struct S { using ns::E::A; };)",
            "int e = S::^A;");
+  testWalk(R"(namespace ns { enum E { $explicit^A = 42 }; })",
+           "namespace z = ns; int e = z::^A;");
 }
 
 TEST(WalkAST, InitializerList) {



More information about the cfe-commits mailing list