From 645ce23b5dbb1d8eb0cc60678ea0aa570ddd19f4 Mon Sep 17 00:00:00 2001 From: Dan Katz Date: Wed, 29 May 2024 22:19:21 -0400 Subject: [PATCH] Mangle reflections of constructors and destructors correctly. Fixes #54. --- clang/lib/AST/ItaniumMangle.cpp | 6 ++++++ .../reflection/template-arguments.pass.cpp | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 7118260ecc1493..b80c9a5d5380bf 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -4694,6 +4694,12 @@ void CXXNameMangler::mangleReflection(const ReflectionValue &R) { Decl *D = R.getAsDecl(); if (auto * ED = dyn_cast(D)) { mangleIntegerLiteral(ED->getType(), ED->getInitVal()); + } else if (auto *CD = dyn_cast(D)) { + GlobalDecl GD(CD, Ctor_Complete); + mangle(GD); + } else if (auto *DD = dyn_cast(D)) { + GlobalDecl GD(DD, Dtor_Complete); + mangle(GD); } else { mangle(cast(D)); } diff --git a/libcxx/test/std/experimental/reflection/template-arguments.pass.cpp b/libcxx/test/std/experimental/reflection/template-arguments.pass.cpp index c2e3a178623767..eb9a5a6b43304d 100644 --- a/libcxx/test/std/experimental/reflection/template-arguments.pass.cpp +++ b/libcxx/test/std/experimental/reflection/template-arguments.pass.cpp @@ -194,8 +194,24 @@ template struct TCls {}; TCls obj1; TCls obj2; -static_assert(has_template_arguments(template_arguments_of(^decltype(obj2))[0]) == - has_template_arguments(^TCls)); +static_assert( + has_template_arguments(template_arguments_of(^decltype(obj2))[0]) == + has_template_arguments(^TCls)); } // namespace bb_clang_p2996_issue_41_regression_test + // ======================================= + // bb_clang_p2996_issue_54_regression_test + // ======================================= + +namespace bb_clang_p2996_issue_54_regression_test { +template void fn() { } + +void fn() { + class S { S(); ~S(); }; + fn(); + fn(); +} +} // namespace bb_clang_p2996_issue_54_regression_test + + int main() { }