r255176 - Fix crash on invalid initialization with std::initializer_list

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 9 15:18:39 PST 2015


Author: rnk
Date: Wed Dec  9 17:18:38 2015
New Revision: 255176

URL: http://llvm.org/viewvc/llvm-project?rev=255176&view=rev
Log:
Fix crash on invalid initialization with std::initializer_list

It is possible for CheckListElementTypes to fail without filling in any
initializer list elements.

Modified:
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=255176&r1=255175&r2=255176&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Dec  9 17:18:38 2015
@@ -805,7 +805,8 @@ void InitListChecker::CheckImplicitInitL
     unsigned EndIndex = (Index == StartIndex? StartIndex : Index - 1);
     // Update the structured sub-object initializer so that it's ending
     // range corresponds with the end of the last initializer it used.
-    if (EndIndex < ParentIList->getNumInits()) {
+    if (EndIndex < ParentIList->getNumInits() &&
+        ParentIList->getInit(EndIndex)) {
       SourceLocation EndLoc
         = ParentIList->getInit(EndIndex)->getSourceRange().getEnd();
       StructuredSubobjectInitList->setRBraceLoc(EndLoc);

Modified: cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=255176&r1=255175&r2=255176&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp Wed Dec  9 17:18:38 2015
@@ -284,3 +284,28 @@ namespace ParameterPackNestedInitializer
 
   void foo() { f({{0}}, {{'\0'}}); }
 }
+
+namespace update_rbrace_loc_crash {
+  // We used to crash-on-invalid on this example when updating the right brace
+  // location.
+  template <typename T, T>
+  struct A {};
+  template <typename T, typename F, int... I>
+  std::initializer_list<T> ExplodeImpl(F p1, A<int, I...>) {
+    // expected-error at +1 {{reference to type 'const update_rbrace_loc_crash::Incomplete' could not bind to an rvalue of type 'void'}}
+    return {p1(I)...};
+  }
+  template <typename T, int N, typename F>
+  void Explode(F p1) {
+    // expected-note at +1 {{in instantiation of function template specialization}}
+    ExplodeImpl<T>(p1, A<int, N>());
+  }
+  class Incomplete;
+  struct ContainsIncomplete {
+    const Incomplete &obstacle;
+  };
+  void f() {
+    // expected-note at +1 {{in instantiation of function template specialization}}
+    Explode<ContainsIncomplete, 4>([](int) {});
+  }
+}




More information about the cfe-commits mailing list