[PATCH] Sema: Subst type default template args earlier

David Majnemer david.majnemer at gmail.com
Sat Aug 24 15:04:16 PDT 2013


Hi doug.gregor, rjmccall, rsmith,

We would not perform substitution at an appropriate point, allow strange
results to appear like accepts things that we shouldn't and creating
incorrect manglings.  Note that this hasn't fixed the other cases like
template-template parameters or non-type template parameters.

http://llvm-reviews.chandlerc.com/D1507

Files:
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/CodeGenCXX/mangle.cpp

Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1737,8 +1737,13 @@
                                  D->isParameterPack());
   Inst->setAccess(AS_public);
 
-  if (D->hasDefaultArgument())
-    Inst->setDefaultArgument(D->getDefaultArgumentInfo(), false);
+  if (D->hasDefaultArgument()) {
+    TypeSourceInfo *InstantiatedDefaultArg =
+        SemaRef.SubstType(D->getDefaultArgumentInfo(), TemplateArgs,
+                          D->getDefaultArgumentLoc(), D->getDeclName());
+    if (InstantiatedDefaultArg)
+      Inst->setDefaultArgument(InstantiatedDefaultArg, false);
+  }
 
   // Introduce this template parameter's instantiation into the instantiation
   // scope.
@@ -1888,7 +1893,8 @@
   if (Invalid)
     Param->setInvalidDecl();
 
-  Param->setDefaultArgument(D->getDefaultArgument(), false);
+  if (D->hasDefaultArgument())
+    Param->setDefaultArgument(D->getDefaultArgument(), false);
 
   // Introduce this template parameter's instantiation into the instantiation
   // scope.
@@ -2011,7 +2017,9 @@
                                              D->getPosition(),
                                              D->isParameterPack(),
                                              D->getIdentifier(), InstParams);
-  Param->setDefaultArgument(D->getDefaultArgument(), false);
+  if (D->hasDefaultArgument())
+    Param->setDefaultArgument(D->getDefaultArgument(), false);
+
   Param->setAccess(AS_public);
 
   // Introduce this template parameter's instantiation into the instantiation
Index: test/CodeGenCXX/mangle.cpp
===================================================================
--- test/CodeGenCXX/mangle.cpp
+++ test/CodeGenCXX/mangle.cpp
@@ -910,3 +910,14 @@
   };
   void g() { f(); }
 }
+
+namespace test41 {
+  // CHECK: define linkonce_odr void @_ZN6test414funcINS_1XEEEvNS_3fooILi20ES1_EE
+  template <int i, class T> struct foo {
+    template <class T2 = T> friend void func(foo x) {}
+  };
+
+  struct X {};
+
+  void g() { func(foo<20, X>()); }
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1507.1.patch
Type: text/x-patch
Size: 2149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130824/66b0f055/attachment.bin>


More information about the cfe-commits mailing list