Refactor InitListChecker to make it a bit clearer that hasError is only
set to true in VerifyOnly mode in cases where it's also set to true when
actually building the initializer list.

Add FIXMEs for the two cases where that's not true. No functionality
change intended.

llvm-svn: 370417
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 83c475a..7c33e99 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1093,49 +1093,32 @@
   if (hadError)
     return;
 
-  if (Index < IList->getNumInits()) {
+  // Don't complain for incomplete types, since we'll get an error elsewhere.
+  if (Index < IList->getNumInits() && !T->isIncompleteType()) {
     // We have leftover initializers
+    bool ExtraInitsIsError = SemaRef.getLangOpts().CPlusPlus ||
+          (SemaRef.getLangOpts().OpenCL && T->isVectorType());
+    hadError = ExtraInitsIsError;
     if (VerifyOnly) {
-      if (SemaRef.getLangOpts().CPlusPlus ||
-          (SemaRef.getLangOpts().OpenCL &&
-           IList->getType()->isVectorType())) {
-        hadError = true;
-      }
       return;
-    }
-
-    if (StructuredIndex == 1 &&
-        IsStringInit(StructuredList->getInit(0), T, SemaRef.Context) ==
-            SIF_None) {
-      unsigned DK = diag::ext_excess_initializers_in_char_array_initializer;
-      if (SemaRef.getLangOpts().CPlusPlus) {
-        DK = diag::err_excess_initializers_in_char_array_initializer;
-        hadError = true;
-      }
-      // Special-case
+    } else if (StructuredIndex == 1 &&
+               IsStringInit(StructuredList->getInit(0), T, SemaRef.Context) ==
+                   SIF_None) {
+      unsigned DK =
+          ExtraInitsIsError
+              ? diag::err_excess_initializers_in_char_array_initializer
+              : diag::ext_excess_initializers_in_char_array_initializer;
       SemaRef.Diag(IList->getInit(Index)->getBeginLoc(), DK)
           << IList->getInit(Index)->getSourceRange();
-    } else if (!T->isIncompleteType()) {
-      // Don't complain for incomplete types, since we'll get an error
-      // elsewhere
-      QualType CurrentObjectType = StructuredList->getType();
-      int initKind =
-        CurrentObjectType->isArrayType()? 0 :
-        CurrentObjectType->isVectorType()? 1 :
-        CurrentObjectType->isScalarType()? 2 :
-        CurrentObjectType->isUnionType()? 3 :
-        4;
+    } else {
+      int initKind = T->isArrayType() ? 0 :
+                     T->isVectorType() ? 1 :
+                     T->isScalarType() ? 2 :
+                     T->isUnionType() ? 3 :
+                     4;
 
-      unsigned DK = diag::ext_excess_initializers;
-      if (SemaRef.getLangOpts().CPlusPlus) {
-        DK = diag::err_excess_initializers;
-        hadError = true;
-      }
-      if (SemaRef.getLangOpts().OpenCL && initKind == 1) {
-        DK = diag::err_excess_initializers;
-        hadError = true;
-      }
-
+      unsigned DK = ExtraInitsIsError ? diag::err_excess_initializers
+                                      : diag::ext_excess_initializers;
       SemaRef.Diag(IList->getInit(Index)->getBeginLoc(), DK)
           << initKind << IList->getInit(Index)->getSourceRange();
     }
@@ -1363,8 +1346,8 @@
         hadError = true;
       else {
         ExprRes = SemaRef.DefaultFunctionArrayLvalueConversion(ExprRes.get());
-          if (ExprRes.isInvalid())
-            hadError = true;
+        if (ExprRes.isInvalid())
+          hadError = true;
       }
       UpdateStructuredListElement(StructuredList, StructuredIndex,
                                   ExprRes.getAs<Expr>());
@@ -1389,10 +1372,15 @@
     ++StructuredIndex;
   } else {
     if (!VerifyOnly) {
-      // We cannot initialize this element, so let
-      // PerformCopyInitialization produce the appropriate diagnostic.
-      SemaRef.PerformCopyInitialization(Entity, SourceLocation(), expr,
-                                        /*TopLevelOfInitList=*/true);
+      // We cannot initialize this element, so let PerformCopyInitialization
+      // produce the appropriate diagnostic. We already checked that this
+      // initialization will fail.
+      ExprResult Copy =
+          SemaRef.PerformCopyInitialization(Entity, SourceLocation(), expr,
+                                            /*TopLevelOfInitList=*/true);
+      (void)Copy;
+      assert(Copy.isInvalid() &&
+             "expected non-aggregate initialization to fail");
     }
     hadError = true;
     ++Index;
@@ -1872,6 +1860,8 @@
     // enough elements, or if we're performing an array new with an unknown
     // bound.
     // FIXME: This needs to detect holes left by designated initializers too.
+    // FIXME: Doing this now is wrong; these holes can be filled by later
+    // designated initializers.
     if ((maxElementsKnown && elementIndex < maxElements) ||
         Entity.isVariableLengthArrayNew())
       CheckEmptyInitializable(
@@ -2132,6 +2122,8 @@
   if (VerifyOnly && Field != FieldEnd && !DeclType->isUnionType() &&
       !Field->getType()->isIncompleteArrayType()) {
     // FIXME: Should check for holes left by designated initializers too.
+    // FIXME: Doing this now is wrong; these holes can be filled by later
+    // designated initializers.
     for (; Field != FieldEnd && !hadError; ++Field) {
       if (!Field->isUnnamedBitfield() && !Field->hasInClassInitializer())
         CheckEmptyInitializable(