File tree 2 files changed +14
-3
lines changed 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) {
1689
1689
if (!Success)
1690
1690
return false ;
1691
1691
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);
1693
1696
// If the index is first, we need to change that.
1694
1697
if (LHS == Index) {
1695
- if (!this ->emitFlip (PT_Ptr, IndexT, E))
1698
+ if (!this ->emitFlip (PT_Ptr, * IndexT, E))
1696
1699
return false ;
1697
1700
}
1698
1701
1699
- return this ->emitArrayElemPtrPop (IndexT, E);
1702
+ return this ->emitArrayElemPtrPop (* IndexT, E);
1700
1703
}
1701
1704
1702
1705
template <class Emitter >
Original file line number Diff line number Diff line change @@ -654,3 +654,11 @@ namespace ZeroSizeTypes {
654
654
// both-warning {{subtraction of pointers to type 'int[0]' of zero size has undefined behavior}}
655
655
}
656
656
}
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