[llvm-branch-commits] [cfe-branch] r195394 - Merging r195384:

Bill Wendling isanbard at gmail.com
Thu Nov 21 16:01:45 PST 2013


Author: void
Date: Thu Nov 21 18:01:44 2013
New Revision: 195394

URL: http://llvm.org/viewvc/llvm-project?rev=195394&view=rev
Log:
Merging r195384:
------------------------------------------------------------------------
r195384 | rsmith | 2013-11-21 15:30:57 -0800 (Thu, 21 Nov 2013) | 2 lines

PR18013: Don't assert diagnosing a bad std::initializer_list construction.

------------------------------------------------------------------------

Modified:
    cfe/branches/release_34/   (props changed)
    cfe/branches/release_34/lib/Sema/SemaInit.cpp
    cfe/branches/release_34/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

Propchange: cfe/branches/release_34/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Nov 21 18:01:44 2013
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:195126,195128,195135-195136,195146,195149,195154,195158,195163,195168,195174,195268,195283,195367
+/cfe/trunk:195126,195128,195135-195136,195146,195149,195154,195158,195163,195168,195174,195268,195283,195367,195384
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_34/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/lib/Sema/SemaInit.cpp?rev=195394&r1=195393&r2=195394&view=diff
==============================================================================
--- cfe/branches/release_34/lib/Sema/SemaInit.cpp (original)
+++ cfe/branches/release_34/lib/Sema/SemaInit.cpp Thu Nov 21 18:01:44 2013
@@ -6293,6 +6293,28 @@ static void emitBadConversionNotes(Sema
   }
 }
 
+static void diagnoseListInit(Sema &S, const InitializedEntity &Entity,
+                             InitListExpr *InitList) {
+  QualType DestType = Entity.getType();
+
+  QualType E;
+  if (S.getLangOpts().CPlusPlus11 && S.isStdInitializerList(DestType, &E)) {
+    QualType ArrayType = S.Context.getConstantArrayType(
+        E.withConst(),
+        llvm::APInt(S.Context.getTypeSize(S.Context.getSizeType()),
+                    InitList->getNumInits()),
+        clang::ArrayType::Normal, 0);
+    InitializedEntity HiddenArray =
+        InitializedEntity::InitializeTemporary(ArrayType);
+    return diagnoseListInit(S, HiddenArray, InitList);
+  }
+
+  InitListChecker DiagnoseInitList(S, Entity, InitList, DestType,
+                                   /*VerifyOnly=*/false);
+  assert(DiagnoseInitList.HadError() &&
+         "Inconsistent init list check result.");
+}
+
 bool InitializationSequence::Diagnose(Sema &S,
                                       const InitializedEntity &Entity,
                                       const InitializationKind &Kind,
@@ -6340,7 +6362,7 @@ bool InitializationSequence::Diagnose(Se
     break;
   case FK_ArrayTypeMismatch:
   case FK_NonConstantArrayInit:
-    S.Diag(Kind.getLocation(), 
+    S.Diag(Kind.getLocation(),
            (Failure == FK_ArrayTypeMismatch
               ? diag::err_array_init_different_type
               : diag::err_array_init_non_constant_array))
@@ -6632,12 +6654,8 @@ bool InitializationSequence::Diagnose(Se
 
   case FK_ListInitializationFailed: {
     // Run the init list checker again to emit diagnostics.
-    InitListExpr* InitList = cast<InitListExpr>(Args[0]);
-    QualType DestType = Entity.getType();
-    InitListChecker DiagnoseInitList(S, Entity, InitList,
-            DestType, /*VerifyOnly=*/false);
-    assert(DiagnoseInitList.HadError() &&
-           "Inconsistent init list check result.");
+    InitListExpr *InitList = cast<InitListExpr>(Args[0]);
+    diagnoseListInit(S, Entity, InitList);
     break;
   }
 

Modified: cfe/branches/release_34/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_34/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=195394&r1=195393&r2=195394&view=diff
==============================================================================
--- cfe/branches/release_34/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
+++ cfe/branches/release_34/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp Thu Nov 21 18:01:44 2013
@@ -225,3 +225,8 @@ namespace RefVersusInitList {
   void f(std::initializer_list<S>);
   void g(S s) { f({S()}); }
 }
+
+namespace PR18013 {
+  int f();
+  std::initializer_list<long (*)()> x = {f}; // expected-error {{cannot initialize an array element of type 'long (*const)()' with an lvalue of type 'int ()': different return type ('long' vs 'int')}}
+}





More information about the llvm-branch-commits mailing list