From 9bcfc343cb73c1d7d4e9380b615224ca128832f4 Mon Sep 17 00:00:00 2001 From: Dan Katz Date: Wed, 25 Jun 2025 10:30:22 -0400 Subject: [PATCH] Handle StructuralValue-type template arguments in define_aggregate. Fixes #159. --- clang/lib/Sema/SemaReflect.cpp | 11 ++++++-- .../reflection/define-aggregate.pass.cpp | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaReflect.cpp b/clang/lib/Sema/SemaReflect.cpp index 07324d30240f..a224219e216f 100644 --- a/clang/lib/Sema/SemaReflect.cpp +++ b/clang/lib/Sema/SemaReflect.cpp @@ -551,8 +551,15 @@ public: SourceLocation()); break; } - // TODO(P2996): Handle other kinds of TemplateArgument - // (e.g., structural). + case TemplateArgument::StructuralValue: { + Expr *E = new (S.Context) OpaqueValueExpr( + DefinitionLoc, TArg.getStructuralValueType(), VK_PRValue); + E = ConstantExpr::Create(S.Context, E, TArg.getAsStructuralValue()); + ParsedTArgs.emplace_back(ParsedTemplateArgument::NonType, E, + SourceLocation()); + break; + } + // TODO(P2996): Handle other kinds of TemplateArgument. default: llvm_unreachable("unimplemented"); } diff --git a/libcxx/test/std/experimental/reflection/define-aggregate.pass.cpp b/libcxx/test/std/experimental/reflection/define-aggregate.pass.cpp index 8c7e7ab2e460..1a9e8e1f4a30 100644 --- a/libcxx/test/std/experimental/reflection/define-aggregate.pass.cpp +++ b/libcxx/test/std/experimental/reflection/define-aggregate.pass.cpp @@ -396,4 +396,31 @@ int_holder_template o2; } // namespace bb_clang_p2996_issue_145_regression_test + // ======================================== + // bb_clang_p2996_issue_159_regression_test + // ======================================== + +namespace bb_clang_p2996_issue_159_regression_test { +template +struct VS; + +template <> +struct VS<^^float>{}; + +consteval { + std::meta::define_aggregate(^^VS<0>, {}); + std::meta::define_aggregate( + std::meta::substitute(^^VS, {std::meta::reflect_constant(1)}), {}); + + std::meta::define_aggregate( + std::meta::substitute(^^VS, {std::meta::reflect_constant(^^int)}), + {}); +} + +VS<1> v1; +VS<^^int> v2; + +} // namespace bb_clang_p2996_issue_159_regression_test + + int main() { }