From d2231c9424d6cbbcecb6f89cc2de5b987327aeaa Mon Sep 17 00:00:00 2001
From: Sebastian Redl <sebastian.redl@getdesigned.at>
Date: Sun, 19 Feb 2012 12:27:43 +0000
Subject: [PATCH] Fix a crash for nested initializer list initialization. Still
 does the wrong thing in CodeGen, in that it never destructs anything.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150922 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Sema/SemaInit.cpp | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index fb97b00ace4..28b99f9e4c3 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -3078,16 +3078,25 @@ static void TryListInitialization(Sema &S,
     TryReferenceListInitialization(S, Entity, Kind, InitList, Sequence);
     return;
   }
-  if (DestType->isRecordType() && !DestType->isAggregateType()) {
-    if (S.getLangOptions().CPlusPlus0x) {
-      Expr *Arg = InitList;
-      // A direct-initializer is not list-syntax, i.e. there's no special
-      // treatment of "A a({1, 2});".
-      TryConstructorInitialization(S, Entity, Kind, &Arg, 1, DestType,
-                    Sequence, Kind.getKind() != InitializationKind::IK_Direct);
-    } else
-      Sequence.SetFailed(InitializationSequence::FK_InitListBadDestinationType);
-    return;
+  if (DestType->isRecordType()) {
+    if (S.RequireCompleteType(InitList->getLocStart(), DestType, S.PDiag())) {
+      Sequence.SetFailed(InitializationSequence::FK_Incomplete);
+      return;
+    }
+
+    if (!DestType->isAggregateType()) {
+      if (S.getLangOptions().CPlusPlus0x) {
+        Expr *Arg = InitList;
+        // A direct-initializer is not list-syntax, i.e. there's no special
+        // treatment of "A a({1, 2});".
+        TryConstructorInitialization(S, Entity, Kind, &Arg, 1, DestType, 
+                                     Sequence,
+                               Kind.getKind() != InitializationKind::IK_Direct);
+      } else
+        Sequence.SetFailed(
+            InitializationSequence::FK_InitListBadDestinationType);
+      return;
+    }
   }
 
   InitListChecker CheckInitList(S, Entity, InitList,
-- 
GitLab