MS ABI: Mangle alias templates used as template-template arguments
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 30 Jul 2014 08:20:03 +0000 (08:20 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 30 Jul 2014 08:20:03 +0000 (08:20 +0000)
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.

llvm-svn: 214290

clang/lib/AST/MicrosoftMangle.cpp
clang/test/CodeGenCXX/mangle-ms-cxx11.cpp

index e6a6d09..0c80ff8 100644 (file)
@@ -1179,11 +1179,21 @@ void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD,
     }
     break;
   }
-  case TemplateArgument::Template:
-    mangleType(cast<TagDecl>(
-        TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl()));
+  case TemplateArgument::Template: {
+    const NamedDecl *ND =
+        TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl();
+    if (const auto *TD = dyn_cast<TagDecl>(ND)) {
+      mangleType(TD);
+    } else if (isa<TypeAliasDecl>(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,
index 373d2b7..cb9c64f 100644 (file)
@@ -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 <typename T>
+struct A {};
+
+template <typename T>
+using AliasA = A<T>;
+
+template <template <typename> class>
+void f() {}
+
+template void f<AliasA>();
+// CHECK-DAG: @"\01??$f@?@PR20047@@YAXXZ"
+}