From fc1480d51fc40423beac47df16e0b5c3c4f3817a Mon Sep 17 00:00:00 2001 From: Dan Katz Date: Sat, 3 May 2025 16:57:13 -0400 Subject: [PATCH] Fix 'bases_of' with aliases. --- clang/lib/AST/ExprConstantMeta.cpp | 6 +++++- .../experimental/reflection/members-and-subobjects.pass.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ExprConstantMeta.cpp b/clang/lib/AST/ExprConstantMeta.cpp index b393fcd7d2f2..1cfa83f58204 100644 --- a/clang/lib/AST/ExprConstantMeta.cpp +++ b/clang/lib/AST/ExprConstantMeta.cpp @@ -1767,7 +1767,11 @@ bool get_ith_base_of(APValue &Result, ASTContext &C, MetaActions &Meta, switch (RV.getReflectionKind()) { case ReflectionKind::Type: { - Decl *typeDecl = findTypeDecl(RV.getReflectedType()); + QualType QT = RV.getReflectedType(); + QT = desugarType(QT, /*UnwrapAliases=*/true, /*DropCV=*/false, + /*DropRefs=*/false); + + Decl *typeDecl = findTypeDecl(QT); if (auto cxxRecordDecl = dyn_cast_or_null(typeDecl)) { Meta.EnsureInstantiated(typeDecl, Range); diff --git a/libcxx/test/std/experimental/reflection/members-and-subobjects.pass.cpp b/libcxx/test/std/experimental/reflection/members-and-subobjects.pass.cpp index a31d6c74247c..32cf1a4c6378 100644 --- a/libcxx/test/std/experimental/reflection/members-and-subobjects.pass.cpp +++ b/libcxx/test/std/experimental/reflection/members-and-subobjects.pass.cpp @@ -329,6 +329,7 @@ struct B1 {}; struct B2 {}; struct B3 {}; struct D1 : public B1, virtual protected B2, private B3 {}; +using Alias = D1; static_assert(bases_of(^^B1, access_context::unchecked()).size() == 0); static_assert(type_of(bases_of(^^D1, access_context::unchecked())[0]) == ^^B1); static_assert(type_of(bases_of(^^D1, access_context::unchecked())[1]) == ^^B2); @@ -346,6 +347,9 @@ static_assert(!is_protected(bases_of(^^D1, access_context::unchecked())[2])); static_assert(is_private(bases_of(^^D1, access_context::unchecked())[2])); static_assert(!is_virtual(bases_of(^^D1, access_context::unchecked())[2])); +static_assert(type_of(bases_of(^^Alias, + access_context::unchecked())[0]) == ^^B1); + template struct D2 : Bases... {}; static_assert(type_of(bases_of(^^D2, access_context::unchecked())[0]) == ^^B1);