From: Reid Kleckner Date: Wed, 9 Dec 2015 23:18:38 +0000 (+0000) Subject: Fix crash on invalid initialization with std::initializer_list X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70aefba4abcc550f0a9cf976c5bdf5aa6e587906;p=clang Fix crash on invalid initialization with std::initializer_list It is possible for CheckListElementTypes to fail without filling in any initializer list elements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255176 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 0f60ad10a3..ba1f140a9e 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -805,7 +805,8 @@ void InitListChecker::CheckImplicitInitList(const InitializedEntity &Entity, 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); diff --git a/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index 3d11964371..060a0f236b 100644 --- a/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp @@ -284,3 +284,28 @@ namespace ParameterPackNestedInitializerLists_PR23904c3 { 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 + struct A {}; + template + std::initializer_list ExplodeImpl(F p1, A) { + // expected-error@+1 {{reference to type 'const update_rbrace_loc_crash::Incomplete' could not bind to an rvalue of type 'void'}} + return {p1(I)...}; + } + template + void Explode(F p1) { + // expected-note@+1 {{in instantiation of function template specialization}} + ExplodeImpl(p1, A()); + } + class Incomplete; + struct ContainsIncomplete { + const Incomplete &obstacle; + }; + void f() { + // expected-note@+1 {{in instantiation of function template specialization}} + Explode([](int) {}); + } +}