diff options
author | Reid Kleckner <rnk@google.com> | 2015-12-09 23:18:38 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2015-12-09 23:18:38 +0000 |
commit | 4a09e8872f37b191e70a0664e687aae38549390c (patch) | |
tree | fb17385d6e1d233250cedcd329b470fad24cbb6f /clang | |
parent | 5d2f7cfd44db983c5c21d36356c3319d792a90bc (diff) | |
download | bcm5719-llvm-4a09e8872f37b191e70a0664e687aae38549390c.tar.gz bcm5719-llvm-4a09e8872f37b191e70a0664e687aae38549390c.zip |
Fix crash on invalid initialization with std::initializer_list
It is possible for CheckListElementTypes to fail without filling in any
initializer list elements.
llvm-svn: 255176
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 3 | ||||
-rw-r--r-- | clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp | 25 |
2 files changed, 27 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 0f60ad10a3e..ba1f140a9e1 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/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/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp b/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp index 3d119643710..060a0f236b4 100644 --- a/clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp +++ b/clang/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 <typename T, T> + struct A {}; + template <typename T, typename F, int... I> + std::initializer_list<T> ExplodeImpl(F p1, A<int, I...>) { + // 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 <typename T, int N, typename F> + void Explode(F p1) { + // expected-note@+1 {{in instantiation of function template specialization}} + ExplodeImpl<T>(p1, A<int, N>()); + } + class Incomplete; + struct ContainsIncomplete { + const Incomplete &obstacle; + }; + void f() { + // expected-note@+1 {{in instantiation of function template specialization}} + Explode<ContainsIncomplete, 4>([](int) {}); + } +} |