forked from OSchip/llvm-project
[Sema] Don't create an invalid source range for overlong initializer lists.
We took both source locations from the end of the initializer list what the code below doesn't expect. This can lead to a crash when rendering the diagnostic (PR24816). Assert that we have more than one element in a scalar initializer with too many elements. llvm-svn: 248391
This commit is contained in:
parent
ff08e926ba
commit
c4284e3aad
|
@ -7047,10 +7047,12 @@ bool InitializationSequence::Diagnose(Sema &S,
|
|||
SourceRange R;
|
||||
|
||||
auto *InitList = dyn_cast<InitListExpr>(Args[0]);
|
||||
if (InitList && InitList->getNumInits() == 1)
|
||||
if (InitList && InitList->getNumInits() >= 1) {
|
||||
R = SourceRange(InitList->getInit(0)->getLocEnd(), InitList->getLocEnd());
|
||||
else
|
||||
} else {
|
||||
assert(Args.size() > 1 && "Expected multiple initializers!");
|
||||
R = SourceRange(Args.front()->getLocEnd(), Args.back()->getLocEnd());
|
||||
}
|
||||
|
||||
R.setBegin(S.getLocForEndOfToken(R.getBegin()));
|
||||
if (Kind.isCStyleOrFunctionalCast())
|
||||
|
|
|
@ -129,3 +129,7 @@ namespace array_addressof {
|
|||
using T = int[5];
|
||||
T *p = &T{1,2,3,4,5}; // expected-error {{taking the address of a temporary object of type 'T' (aka 'int [5]')}}
|
||||
}
|
||||
|
||||
namespace PR24816 {
|
||||
struct { int i; } ne = {{0, 1}}; // expected-error{{excess elements in scalar initializer}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue