aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-11-11 02:41:58 +0000
committerJohn McCall <rjmccall@apple.com>2009-11-11 02:41:58 +0000
commita52ef08b26420c8b7208c2fe7f3daf8802b22dd7 (patch)
tree65959852236a03ce8babd25560be6c34ce6f1d1d /lib/Sema/SemaExpr.cpp
parent88b11de727b3a6b81138145cd2f5f2a20592f6ee (diff)
Apparently the following idiom is specifically encouraged:
if (self = [super init]) Recognize it and only warn if -Wparentheses is explicitly enabled. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86790 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index c29cfb7c5d..6bdcb0ed90 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -6510,11 +6510,22 @@ bool Sema::CheckCallReturnType(QualType ReturnType, SourceLocation Loc,
void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
SourceLocation Loc;
+ unsigned diagnostic = diag::warn_condition_is_assignment;
+
if (isa<BinaryOperator>(E)) {
BinaryOperator *Op = cast<BinaryOperator>(E);
if (Op->getOpcode() != BinaryOperator::Assign)
return;
+ // Greylist the following Cocoa ObjC idiom by putting it into a
+ // warning subcategory which defaults off:
+ // if (self = [super init])
+ // The selector can vary, and it's possible that the base might,
+ // too, so we just recognize any message call.
+ if (isSelfExpr(Op->getLHS()) &&
+ isa<ObjCMessageExpr>(Op->getRHS()->IgnoreParenCasts()))
+ diagnostic = diag::warn_condition_is_self_assignment;
+
Loc = Op->getOperatorLoc();
} else if (isa<CXXOperatorCallExpr>(E)) {
CXXOperatorCallExpr *Op = cast<CXXOperatorCallExpr>(E);
@@ -6530,7 +6541,7 @@ void Sema::DiagnoseAssignmentAsCondition(Expr *E) {
SourceLocation Open = E->getSourceRange().getBegin();
SourceLocation Close = PP.getLocForEndOfToken(E->getSourceRange().getEnd());
- Diag(Loc, diag::warn_condition_is_assignment)
+ Diag(Loc, diagnostic)
<< E->getSourceRange()
<< CodeModificationHint::CreateInsertion(Open, "(")
<< CodeModificationHint::CreateInsertion(Close, ")");