File tree 2 files changed +16
-7
lines changed 2 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -1695,9 +1695,6 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
1695
1695
const Expr *Index = E->getIdx ();
1696
1696
const Expr *Base = E->getBase ();
1697
1697
1698
- if (DiscardResult)
1699
- return this ->discard (LHS) && this ->discard (RHS);
1700
-
1701
1698
// C++17's rules require us to evaluate the LHS first, regardless of which
1702
1699
// side is the base.
1703
1700
bool Success = true ;
@@ -1728,7 +1725,11 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
1728
1725
return false ;
1729
1726
}
1730
1727
1731
- return this ->emitArrayElemPtrPop (*IndexT, E);
1728
+ if (!this ->emitArrayElemPtrPop (*IndexT, E))
1729
+ return false ;
1730
+ if (DiscardResult)
1731
+ return this ->emitPopPtr (E);
1732
+ return true ;
1732
1733
}
1733
1734
1734
1735
template <class Emitter >
Original file line number Diff line number Diff line change 1
- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s
2
- // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify=expected,both %s
3
- // RUN: %clang_cc1 -verify=ref,both %s
1
+ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both %s
2
+ // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both - std=c++20 %s
3
+ // RUN: %clang_cc1 -verify=ref,both %s
4
4
// RUN: %clang_cc1 -verify=ref,both -std=c++20 %s
5
5
6
6
constexpr int m = 3 ;
@@ -771,3 +771,11 @@ namespace OnePastEndDiag {
771
771
constexpr int k = a(foo + 2 ); // both-error {{must be initialized by a constant expression}} \
772
772
// both-note {{in call to 'a(&foo[2])'}}
773
773
}
774
+
775
+ namespace DiscardedSubScriptExpr {
776
+ constexpr bool foo () { // both-error {{never produces a constant expression}}
777
+ int a[2 ] = {};
778
+ (void )a[3 ]; // both-note {{cannot refer to element 3 of array of 2 elements in a constant expression}}
779
+ return true ;
780
+ }
781
+ }
You can’t perform that action at this time.
0 commit comments