From 78a73973fb70ddcb51768489df7b273c45df9111 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov Date: Fri, 29 Aug 2025 21:16:55 -0300 Subject: [PATCH] [clang] fix obtaining EnumDecl for UsingEnumDecl Use the castAs acessor for the type for a UsingEnumDecl, as it can be sugar for an EnumType. Fixes a regression reported here: https://github.com/llvm/llvm-project/pull/155313#issuecomment-3238482327 Since this regression was never released, there are no release notes. --- clang/include/clang/AST/DeclCXX.h | 2 +- clang/test/SemaTemplate/using-decl.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 00d8f724671f1..8802664031d37 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -3826,7 +3826,7 @@ class UsingEnumDecl : public BaseUsingDecl, public Mergeable { public: EnumDecl *getEnumDecl() const { - return cast(EnumType->getType())->getOriginalDecl(); + return EnumType->getType()->castAs()->getOriginalDecl(); } static UsingEnumDecl *Create(ASTContext &C, DeclContext *DC, diff --git a/clang/test/SemaTemplate/using-decl.cpp b/clang/test/SemaTemplate/using-decl.cpp index 1ef2a2dfaa019..d54d3a3f3ea9e 100644 --- a/clang/test/SemaTemplate/using-decl.cpp +++ b/clang/test/SemaTemplate/using-decl.cpp @@ -14,3 +14,15 @@ namespace UsingInGenericLambda { } void e() { c(); } } + +namespace UsingUsingEnum { + namespace foo { + enum class EnumOne {}; + } + using foo::EnumOne; + + template void t() { + using enum EnumOne; + } + template void t(); +} // namespace UsingUsingEnum