aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/AST/Expr.cpp4
-rw-r--r--lib/Sema/SemaStmt.cpp4
-rw-r--r--test/Sema/switch.c11
3 files changed, 15 insertions, 4 deletions
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index c38cec32c3..68fcb35c79 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -52,7 +52,9 @@ bool Expr::isKnownToHaveBooleanValue() const {
}
}
- if (const CastExpr *CE = dyn_cast<CastExpr>(this))
+ // Only look through implicit casts. If the user writes
+ // '(int) (a && b)' treat it as an arbitrary int.
+ if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(this))
return CE->getSubExpr()->isKnownToHaveBooleanValue();
if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(this)) {
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 875b160d71..0c510fb1dd 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -400,9 +400,7 @@ static bool EqEnumVals(const std::pair<llvm::APSInt, EnumConstantDecl*>& lhs,
/// GetTypeBeforeIntegralPromotion - Returns the pre-promotion type of
/// potentially integral-promoted expression @p expr.
static QualType GetTypeBeforeIntegralPromotion(const Expr* expr) {
- const ImplicitCastExpr *ImplicitCast =
- dyn_cast_or_null<ImplicitCastExpr>(expr);
- if (ImplicitCast != NULL) {
+ if (const CastExpr *ImplicitCast = dyn_cast<ImplicitCastExpr>(expr)) {
const Expr *ExprBeforePromotion = ImplicitCast->getSubExpr();
QualType TypeBeforePromotion = ExprBeforePromotion->getType();
if (TypeBeforePromotion->isIntegralType()) {
diff --git a/test/Sema/switch.c b/test/Sema/switch.c
index 27ad06657e..bb4822916c 100644
--- a/test/Sema/switch.c
+++ b/test/Sema/switch.c
@@ -277,3 +277,14 @@ void test16() {
case '6': return;
}
}
+
+// PR7359
+void test17(int x) {
+ switch (x >= 17) { // expected-warning {{switch condition has boolean value}}
+ case 0: return;
+ }
+
+ switch ((int) (x <= 17)) {
+ case 0: return;
+ }
+}