aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-07-09 16:54:44 +0000
committerJordan Rose <jordan_rose@apple.com>2012-07-09 16:54:44 +0000
commit6deae7cc8de2fb7578ed244d064cd34af744aac5 (patch)
treecc986f8896a349f8f3d39b3e5c0237650ef28d9e /lib
parent2964ffed269794cb6d13d58a287001d2d4433a55 (diff)
Downgrade the "direct comparison" error for ObjC literals to a warning.
Chris pointed out that while the comparison is certainly problematic and does not have well-defined behavior, it isn't any worse than some of the other abuses that we merely warn about and doesn't need to make the compilation fail. Revert the release notes change (r159766) now that this is just a new warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159939 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Sema/SemaExpr.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 6dbf704765..fbd70a8d26 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -6739,7 +6739,7 @@ static DiagnosticBuilder diagnoseObjCLiteralComparison(Sema &S,
llvm_unreachable("Unknown Objective-C object literal kind");
}
- return S.Diag(Loc, diag::err_objc_literal_comparison)
+ return S.Diag(Loc, diag::warn_objc_literal_comparison)
<< LiteralKind << CanFix << Literal->getSourceRange();
}
@@ -6747,6 +6747,14 @@ static ExprResult fixObjCLiteralComparison(Sema &S, SourceLocation OpLoc,
ExprResult &LHS,
ExprResult &RHS,
BinaryOperatorKind Op) {
+ // Check early to see if the warning's on.
+ // If it's off, we should /not/ be auto-applying the accompanying fixit.
+ DiagnosticsEngine::Level Level =
+ S.getDiagnostics().getDiagnosticLevel(diag::warn_objc_literal_comparison,
+ OpLoc);
+ if (Level == DiagnosticsEngine::Ignored)
+ return ExprEmpty();
+
assert((Op == BO_EQ || Op == BO_NE) && "Cannot fix other operations.");
// Get the LHS object's interface type.
@@ -8228,12 +8236,14 @@ ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc,
break;
case BO_EQ:
case BO_NE:
- if (isObjCObjectLiteral(LHS) || isObjCObjectLiteral(RHS)) {
- ExprResult IsEqualCall = fixObjCLiteralComparison(*this, OpLoc,
- LHS, RHS, Opc);
- if (IsEqualCall.isUsable())
- return IsEqualCall;
- // Otherwise, fall back to the normal diagnostic in CheckCompareOperands.
+ if (getLangOpts().ObjC1) {
+ if (isObjCObjectLiteral(LHS) || isObjCObjectLiteral(RHS)) {
+ ExprResult IsEqualCall = fixObjCLiteralComparison(*this, OpLoc,
+ LHS, RHS, Opc);
+ if (IsEqualCall.isUsable())
+ return IsEqualCall;
+ // Otherwise, fall back to the normal warning in CheckCompareOperands.
+ }
}
ResultTy = CheckCompareOperands(LHS, RHS, OpLoc, Opc, false);
break;