Skip to content

[clang] fix unresolved dependent template specialization mangling #135111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions clang/lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,9 +1404,19 @@ void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
// - a template type parameter
// - a template template parameter with arguments
// In all of these cases, we should have no prefix.
if (qualifier->getPrefix()) {
mangleUnresolvedPrefix(qualifier->getPrefix(),
/*recursive*/ true);
if (NestedNameSpecifier *Prefix = qualifier->getPrefix()) {
if (const auto *DTST =
dyn_cast<DependentTemplateSpecializationType>(type)) {
Out << "srN";
TemplateName Template = getASTContext().getDependentTemplateName(
{Prefix, DTST->getDependentTemplateName().getName(),
/*HasTemplateKeyword=*/true});
mangleTemplatePrefix(Template);
mangleTemplateArgs(Template, DTST->template_arguments());
break;
}
mangleUnresolvedPrefix(Prefix,
/*recursive=*/true);
} else {
// Otherwise, all the cases want this.
Out << "sr";
Expand Down
21 changes: 19 additions & 2 deletions clang/test/CodeGenCXX/mangle-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace test7 {
static const unsigned value = sizeof(T);
};

template<unsigned> struct int_c {
template<unsigned> struct int_c {
typedef float type;
};

Expand All @@ -92,7 +92,7 @@ namespace test8 {
};
};

template<unsigned> struct int_c {
template<unsigned> struct int_c {
typedef float type;
};

Expand Down Expand Up @@ -399,3 +399,20 @@ namespace type_qualifier {
// CHECK: @_ZN14type_qualifier1gIPiEEvDTcmcvv_ELi1EE
template void g<int*>(int);
}

namespace unresolved_template_specialization_type {
template <int> struct enable_if {};
struct Foo {
static const int value = true;
};
struct HashStateBase {
template <typename> using is_hashable = Foo;
};
template <class> struct raw_hash_set {
template <typename H>
static enable_if<H::template is_hashable<int>::value>
AbslHashValue() {}
};
template enable_if<true> raw_hash_set<int>::AbslHashValue<HashStateBase>();
// CHECH: @_ZN39unresolved_template_specialization_type12raw_hash_setIiE13AbslHashValueINS_13HashStateBaseEEENS_9enable_ifIXsrNT_11is_hashableIiEE5valueEEEv
} // namespace unresolved_template_specialization_type