@@ -153,7 +153,8 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
153153 if (RHS.isNegative ()) {
154154 const SourceInfo &Loc = S.Current ->getSource (OpPC);
155155 S.CCEDiag (Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt ();
156- return false ;
156+ if (!S.noteUndefinedBehavior ())
157+ return false ;
157158 }
158159
159160 // C++11 [expr.shift]p1: Shift width must be less than the bit width of
@@ -163,17 +164,24 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
163164 const APSInt Val = RHS.toAPSInt ();
164165 QualType Ty = E->getType ();
165166 S.CCEDiag (E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
166- return !(S.getEvalStatus ().Diag && !S.getEvalStatus ().Diag ->empty () && S.getLangOpts ().CPlusPlus11 );
167+ if (!S.noteUndefinedBehavior ())
168+ return false ;
167169 }
168170
169171 if (LHS.isSigned () && !S.getLangOpts ().CPlusPlus20 ) {
170172 const Expr *E = S.Current ->getExpr (OpPC);
171173 // C++11 [expr.shift]p2: A signed left shift must have a non-negative
172174 // operand, and must not overflow the corresponding unsigned type.
173- if (LHS.isNegative ())
175+ if (LHS.isNegative ()) {
174176 S.CCEDiag (E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt ();
175- else if (LHS.toUnsigned ().countLeadingZeros () < static_cast <unsigned >(RHS))
177+ if (!S.noteUndefinedBehavior ())
178+ return false ;
179+ } else if (LHS.toUnsigned ().countLeadingZeros () <
180+ static_cast <unsigned >(RHS)) {
176181 S.CCEDiag (E, diag::note_constexpr_lshift_discards);
182+ if (!S.noteUndefinedBehavior ())
183+ return false ;
184+ }
177185 }
178186
179187 // C++2a [expr.shift]p2: [P0907R4]:
@@ -2269,8 +2277,7 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS) {
22692277 // shift is not a constant expression.
22702278 const SourceInfo &Loc = S.Current ->getSource (OpPC);
22712279 S.CCEDiag (Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt ();
2272- if (S.getLangOpts ().CPlusPlus11 && S.getEvalStatus ().Diag &&
2273- !S.getEvalStatus ().Diag ->empty ())
2280+ if (!S.noteUndefinedBehavior ())
22742281 return false ;
22752282 RHS = -RHS;
22762283 return DoShift < LT, RT,
@@ -2286,8 +2293,7 @@ inline bool DoShift(InterpState &S, CodePtr OpPC, LT &LHS, RT &RHS) {
22862293 // E1 x 2^E2 module 2^N.
22872294 const SourceInfo &Loc = S.Current ->getSource (OpPC);
22882295 S.CCEDiag (Loc, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt ();
2289- if (S.getLangOpts ().CPlusPlus11 && S.getEvalStatus ().Diag &&
2290- !S.getEvalStatus ().Diag ->empty ())
2296+ if (!S.noteUndefinedBehavior ())
22912297 return false ;
22922298 }
22932299 }
0 commit comments