From 529ef5ef773c8e634eefebf79faf2f4f4d249816 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 30 Jul 2014 08:20:03 +0000 Subject: [PATCH] MS ABI: Mangle alias templates used as template-template arguments A templated using declaration may be used as a template-template argument. Unfortunately, the VS "14" chooses '?' as the sole marker for the argument. This is problematic because it presupposes the possibility of using more than one template-aliases as arguments to the same template. This fixes PR20047. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214290 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftMangle.cpp | 16 +++++++++++++--- test/CodeGenCXX/mangle-ms-cxx11.cpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index e6a6d09b48..0c80ff814c 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -1179,11 +1179,21 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD, } break; } - case TemplateArgument::Template: - mangleType(cast( - TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl())); + case TemplateArgument::Template: { + const NamedDecl *ND = + TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl(); + if (const auto *TD = dyn_cast(ND)) { + mangleType(TD); + } else if (isa(ND)) { + // FIXME: The mangling, while compatible with VS "14", is horribly + // broken. Update this when they release their next compiler. + Out << '?'; + } else { + llvm_unreachable("unexpected template template NamedDecl!"); + } break; } + } } void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals, diff --git a/test/CodeGenCXX/mangle-ms-cxx11.cpp b/test/CodeGenCXX/mangle-ms-cxx11.cpp index 373d2b7b95..cb9c64fc9a 100644 --- a/test/CodeGenCXX/mangle-ms-cxx11.cpp +++ b/test/CodeGenCXX/mangle-ms-cxx11.cpp @@ -139,3 +139,17 @@ void templ_fun_with_pack() {} template void templ_fun_with_pack<>(); // CHECK-DAG: @"\01??$templ_fun_with_pack@$S@@YAXXZ" + +namespace PR20047 { +template +struct A {}; + +template +using AliasA = A; + +template