File tree Expand file tree Collapse file tree 2 files changed +16
-7
lines changed Expand file tree Collapse file tree 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) {
16951695 const Expr *Index = E->getIdx ();
16961696 const Expr *Base = E->getBase ();
16971697
1698- if (DiscardResult)
1699- return this ->discard (LHS) && this ->discard (RHS);
1700-
17011698 // C++17's rules require us to evaluate the LHS first, regardless of which
17021699 // side is the base.
17031700 bool Success = true ;
@@ -1728,7 +1725,11 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
17281725 return false ;
17291726 }
17301727
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 ;
17321733}
17331734
17341735template <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
44// RUN: %clang_cc1 -verify=ref,both -std=c++20 %s
55
66constexpr int m = 3 ;
@@ -771,3 +771,11 @@ namespace OnePastEndDiag {
771771 constexpr int k = a(foo + 2 ); // both-error {{must be initialized by a constant expression}} \
772772 // both-note {{in call to 'a(&foo[2])'}}
773773}
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