Correctly parse braced member initializers (even in delayed parsing) and correctly pass
the information on to Sema. There's still an incorrectness in the way template instantiation
works now, but that is due to a far larger underlying representational problem.
Also add a test case for various list initialization cases of scalars, which test this
commit as well as the previous one.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140460 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 43db5cb..e29b75a 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2670,6 +2670,19 @@
   }
 }
 
+static MultiInitializer CreateMultiInitializer(
+                        const SmallVectorImpl<Expr*> &Args,
+                        const CXXCtorInitializer *Init) {
+  // FIXME: This is a hack that will do slightly the wrong thing for an
+  // initializer of the form foo({...}).
+  // The right thing to do would be to modify InstantiateInitializer to create
+  // the MultiInitializer.
+  if (Args.size() == 1 && isa<InitListExpr>(Args[0]))
+    return MultiInitializer(Args[0]);
+  return MultiInitializer(Init->getLParenLoc(), (Expr **)Args.data(),
+                          Args.size(), Init->getRParenLoc());
+}
+
 void
 Sema::InstantiateMemInitializers(CXXConstructorDecl *New,
                                  const CXXConstructorDecl *Tmpl,
@@ -2736,12 +2749,9 @@
         }
 
         // Build the initializer.
-        MemInitResult NewInit = BuildBaseInitializer(BaseTInfo->getType(), 
-                                                     BaseTInfo,
-                                                     (Expr **)NewArgs.data(),
-                                                     NewArgs.size(),
-                                                     Init->getLParenLoc(),
-                                                     Init->getRParenLoc(),
+        MultiInitializer MultiInit(CreateMultiInitializer(NewArgs, Init));
+        MemInitResult NewInit = BuildBaseInitializer(BaseTInfo->getType(),
+                                                     BaseTInfo, MultiInit,
                                                      New->getParent(),
                                                      SourceLocation());
         if (NewInit.isInvalid()) {
@@ -2774,14 +2784,10 @@
         New->setInvalidDecl();
         continue;
       }
-      
-      NewInit = BuildBaseInitializer(BaseTInfo->getType(), BaseTInfo,
-                                     (Expr **)NewArgs.data(),
-                                     NewArgs.size(),
-                                     Init->getLParenLoc(),
-                                     Init->getRParenLoc(),
-                                     New->getParent(),
-                                     EllipsisLoc);
+
+      MultiInitializer MultiInit(CreateMultiInitializer(NewArgs, Init));
+      NewInit = BuildBaseInitializer(BaseTInfo->getType(), BaseTInfo, MultiInit,
+                                     New->getParent(), EllipsisLoc);
     } else if (Init->isMemberInitializer()) {
       FieldDecl *Member = cast_or_null<FieldDecl>(FindInstantiatedDecl(
                                                      Init->getMemberLocation(),
@@ -2793,11 +2799,9 @@
         continue;
       }
 
-      NewInit = BuildMemberInitializer(Member, (Expr **)NewArgs.data(),
-                                       NewArgs.size(),
-                                       Init->getSourceLocation(),
-                                       Init->getLParenLoc(),
-                                       Init->getRParenLoc());
+      MultiInitializer MultiInit(CreateMultiInitializer(NewArgs, Init));
+      NewInit = BuildMemberInitializer(Member, MultiInit,
+                                       Init->getSourceLocation());
     } else if (Init->isIndirectMemberInitializer()) {
       IndirectFieldDecl *IndirectMember =
          cast_or_null<IndirectFieldDecl>(FindInstantiatedDecl(
@@ -2807,14 +2811,12 @@
       if (!IndirectMember) {
         AnyErrors = true;
         New->setInvalidDecl();
-        continue;        
+        continue;
       }
-      
-      NewInit = BuildMemberInitializer(IndirectMember, (Expr **)NewArgs.data(),
-                                       NewArgs.size(),
-                                       Init->getSourceLocation(),
-                                       Init->getLParenLoc(),
-                                       Init->getRParenLoc());
+
+      MultiInitializer MultiInit(CreateMultiInitializer(NewArgs, Init));
+      NewInit = BuildMemberInitializer(IndirectMember, MultiInit,
+                                       Init->getSourceLocation());
     }
 
     if (NewInit.isInvalid()) {