summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2019-06-25 01:45:26 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2019-06-25 01:45:26 +0000
commit7939ba08ab42922a00b7f1b7e4761c7f9cc51f0c (patch)
treedc56e20bcaa28f707ad3f87372eeefab7a8cd5a0 /clang/lib/Sema/SemaExpr.cpp
parent079924b0b7fe5ee62ec9b9e4346544d147c781eb (diff)
downloadbcm5719-llvm-7939ba08ab42922a00b7f1b7e4761c7f9cc51f0c.tar.gz
bcm5719-llvm-7939ba08ab42922a00b7f1b7e4761c7f9cc51f0c.zip
[cxx2a] P1236R1: the validity of a left shift does not depend on the
value of the LHS operand. llvm-svn: 364265
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 99508b1cc35..94ee9e185ea 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9645,9 +9645,11 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
return;
// When left shifting an ICE which is signed, we can check for overflow which
- // according to C++ has undefined behavior ([expr.shift] 5.8/2). Unsigned
- // integers have defined behavior modulo one more than the maximum value
- // representable in the result type, so never warn for those.
+ // according to C++ standards prior to C++2a has undefined behavior
+ // ([expr.shift] 5.8/2). Unsigned integers have defined behavior modulo one
+ // more than the maximum value representable in the result type, so never
+ // warn for those. (FIXME: Unsigned left-shift overflow in a constant
+ // expression is still probably a bug.)
Expr::EvalResult LHSResult;
if (LHS.get()->isValueDependent() ||
LHSType->hasUnsignedIntegerRepresentation() ||
@@ -9656,8 +9658,9 @@ static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS,
llvm::APSInt Left = LHSResult.Val.getInt();
// If LHS does not have a signed type and non-negative value
- // then, the behavior is undefined. Warn about it.
- if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined()) {
+ // then, the behavior is undefined before C++2a. Warn about it.
+ if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined() &&
+ !S.getLangOpts().CPlusPlus2a) {
S.DiagRuntimeBehavior(Loc, LHS.get(),
S.PDiag(diag::warn_shift_lhs_negative)
<< LHS.get()->getSourceRange());
OpenPOWER on IntegriCloud