]> granicus.if.org Git - clang/commitdiff
When we're instantiating a direct variable initializer that has a pack
authorDouglas Gregor <dgregor@apple.com>
Fri, 14 Jan 2011 17:12:22 +0000 (17:12 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 14 Jan 2011 17:12:22 +0000 (17:12 +0000)
expansion in it, we may end up instantiating to an empty
expression-list. In this case, the variable is uninitialized; tweak
the instantiation logic to handle this case. Fixes PR8977.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123449 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CXX/temp/temp.decls/temp.variadic/p4.cpp

index 6b5713a2fa2ddc84c1f1f7a28937c9041dbbb21c..bd431a11386bd7209ac125c625a161fc47f13de6 100644 (file)
@@ -314,19 +314,19 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
     ASTOwningVector<Expr*> InitArgs(SemaRef);
     if (!InstantiateInitializer(SemaRef, D->getInit(), TemplateArgs, LParenLoc,
                                 InitArgs, RParenLoc)) {
-      // Attach the initializer to the declaration.
-      if (D->hasCXXDirectInitializer()) {
+      // Attach the initializer to the declaration, if we have one.
+      if (InitArgs.size() == 0)
+        SemaRef.ActOnUninitializedDecl(Var, false);    
+      else if (D->hasCXXDirectInitializer()) {
         // Add the direct initializer to the declaration.
         SemaRef.AddCXXDirectInitializerToDecl(Var,
                                               LParenLoc,
                                               move_arg(InitArgs),
                                               RParenLoc);
-      } else if (InitArgs.size() == 1) {
+      } else {
+        assert(InitArgs.size() == 1);
         Expr *Init = InitArgs.take()[0];
         SemaRef.AddInitializerToDecl(Var, Init, false);
-      } else {
-        assert(InitArgs.size() == 0);
-        SemaRef.ActOnUninitializedDecl(Var, false);    
       }
     } else {
       // FIXME: Not too happy about invalidating the declaration
index b865d51411ea9768738ecedbe65718f662f3e944..e2fa122937258d428875203f73c8f1fc346e12eb 100644 (file)
@@ -34,6 +34,15 @@ void initializer_list_expansion() {
 template void initializer_list_expansion<1, 2, 3, 4, 5>();
 template void initializer_list_expansion<1, 2, 3, 4, 5, 6>(); // expected-note{{in instantiation of function template specialization 'initializer_list_expansion<1, 2, 3, 4, 5, 6>' requested here}}
 
+namespace PR8977 {
+  struct A { };
+  template<typename T, typename... Args> void f(Args... args) {
+    T t(args...);
+  };
+
+  template void f<A>();
+}
+
 // In a base-specifier-list (Clause 10); the pattern is a base-specifier.
 template<typename ...Mixins>
 struct HasMixins : public Mixins... {