diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-16 21:00:12 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2010-11-16 21:00:12 +0000 |
| commit | f89a56c74b3526d965acb1225ec4f482aeb93e6e (patch) | |
| tree | 42c7b519e8859ecfbaf4d5db8f9f3dd3254ce19b /clang/lib | |
| parent | a9e9593d4920dd52704a045c744ea978756b6123 (diff) | |
| download | bcm5719-llvm-f89a56c74b3526d965acb1225ec4f482aeb93e6e.tar.gz bcm5719-llvm-f89a56c74b3526d965acb1225ec4f482aeb93e6e.zip | |
Warn about arg1 && arg2 || arg3, as GCC 4.3+ does. Fixes rdar://8659922
llvm-svn: 119381
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 7555af375f7..80ee2963a72 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7329,13 +7329,33 @@ static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc, rhs->getSourceRange()); } +static void DiagnoseLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc, + Expr *E) { + if (BinaryOperator *Bop = dyn_cast<BinaryOperator>(E)) { + if (Bop->getOpcode() == BO_LAnd) { + SuggestParentheses(Self, OpLoc, + Self.PDiag(diag::warn_logical_and_in_logical_or) + << E->getSourceRange(), + Self.PDiag(diag::note_logical_and_in_logical_or_silence), + E->getSourceRange(), + Self.PDiag(0), SourceRange()); + } + } +} + /// DiagnoseBinOpPrecedence - Emit warnings for expressions with tricky -/// precedence. This currently diagnoses only "arg1 'bitwise' arg2 'eq' arg3". -/// But it could also warn about arg1 && arg2 || arg3, as GCC 4.3+ does. +/// precedence. static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperatorKind Opc, SourceLocation OpLoc, Expr *lhs, Expr *rhs){ + // Diagnose "arg1 'bitwise' arg2 'eq' arg3". if (BinaryOperator::isBitwiseOp(Opc)) - DiagnoseBitwisePrecedence(Self, Opc, OpLoc, lhs, rhs); + return DiagnoseBitwisePrecedence(Self, Opc, OpLoc, lhs, rhs); + + /// Warn about arg1 && arg2 || arg3, as GCC 4.3+ does. + if (Opc == BO_LOr) { + DiagnoseLogicalAndInLogicalOr(Self, OpLoc, lhs); + DiagnoseLogicalAndInLogicalOr(Self, OpLoc, rhs); + } } // Binary Operators. 'Tok' is the token for the operator. |

