File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -1689,14 +1689,17 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
16891689 if (!Success)
16901690 return false ;
16911691
1692- PrimType IndexT = classifyPrim (Index->getType ());
1692+ std::optional<PrimType> IndexT = classify (Index->getType ());
1693+ // In error-recovery cases, the index expression has a dependent type.
1694+ if (!IndexT)
1695+ return this ->emitError (E);
16931696 // If the index is first, we need to change that.
16941697 if (LHS == Index) {
1695- if (!this ->emitFlip (PT_Ptr, IndexT, E))
1698+ if (!this ->emitFlip (PT_Ptr, * IndexT, E))
16961699 return false ;
16971700 }
16981701
1699- return this ->emitArrayElemPtrPop (IndexT, E);
1702+ return this ->emitArrayElemPtrPop (* IndexT, E);
17001703}
17011704
17021705template <class Emitter >
Original file line number Diff line number Diff line change @@ -654,3 +654,11 @@ namespace ZeroSizeTypes {
654654 // both-warning {{subtraction of pointers to type 'int[0]' of zero size has undefined behavior}}
655655 }
656656}
657+
658+ namespace InvalidIndex {
659+ constexpr int foo (int i) { // both-error {{no return statement in constexpr function}}
660+ int a[] = {1 ,2 ,3 };
661+ return a[_z]; // both-error {{use of undeclared identifier}}
662+ }
663+ static_assert (foo(0 ) == 1 , " " );
664+ }
You can’t perform that action at this time.
0 commit comments