@@ -2390,7 +2390,7 @@ static inline bool DecPtr(InterpState &S, CodePtr OpPC) {
23902390// / 2) Pops another Pointer from the stack.
23912391// / 3) Pushes the difference of the indices of the two pointers on the stack.
23922392template <PrimType Name, class T = typename PrimConv<Name>::T>
2393- inline bool SubPtr (InterpState &S, CodePtr OpPC) {
2393+ inline bool SubPtr (InterpState &S, CodePtr OpPC, bool ElemSizeIsZero ) {
23942394 const Pointer &LHS = S.Stk .pop <Pointer>();
23952395 const Pointer &RHS = S.Stk .pop <Pointer>();
23962396
@@ -2402,25 +2402,23 @@ inline bool SubPtr(InterpState &S, CodePtr OpPC) {
24022402 return false ;
24032403 }
24042404
2405- if (LHS == RHS ) {
2406- S. Stk . push <T> ();
2407- return true ;
2408- }
2405+ if (ElemSizeIsZero ) {
2406+ QualType PtrT = LHS. getType ();
2407+ while ( auto *AT = dyn_cast<ArrayType>(PtrT))
2408+ PtrT = AT-> getElementType ();
24092409
2410- for ( const Pointer &P : {LHS, RHS}) {
2411- if (P. isZeroSizeArray ()) {
2412- QualType PtrT = P. getType ();
2413- while ( auto *AT = dyn_cast<ArrayType>(PtrT) )
2414- PtrT = AT-> getElementType () ;
2410+ QualType ArrayTy = S. getASTContext (). getConstantArrayType (
2411+ PtrT, APInt::getZero ( 1 ), nullptr , ArraySizeModifier::Normal, 0 );
2412+ S. FFDiag (S. Current -> getSource (OpPC),
2413+ diag::note_constexpr_pointer_subtraction_zero_size )
2414+ << ArrayTy ;
24152415
2416- QualType ArrayTy = S.getASTContext ().getConstantArrayType (
2417- PtrT, APInt::getZero (1 ), nullptr , ArraySizeModifier::Normal, 0 );
2418- S.FFDiag (S.Current ->getSource (OpPC),
2419- diag::note_constexpr_pointer_subtraction_zero_size)
2420- << ArrayTy;
2416+ return false ;
2417+ }
24212418
2422- return false ;
2423- }
2419+ if (LHS == RHS) {
2420+ S.Stk .push <T>();
2421+ return true ;
24242422 }
24252423
24262424 int64_t A64 =
0 commit comments