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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248391
91177308-0d34-0410-b5e6-
96231b3b80d8
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())
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}}
+}