diff options
author | Matt Beaumont-Gay <matthewbg@google.com> | 2011-08-15 17:50:06 +0000 |
---|---|---|
committer | Matt Beaumont-Gay <matthewbg@google.com> | 2011-08-15 17:50:06 +0000 |
commit | 9b127f3b44e685cbe513595b7e0115b0884b0604 (patch) | |
tree | f46b0fec21e9da2ecfa350a98145cce77dd9c804 /lib | |
parent | f20d27288c7f124dcc9c50c7c6bf766d522ceb31 (diff) |
Add fixit notes for -Wconstant-logical-operand.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137620 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index efc05de90e..20d129da99 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -6719,9 +6719,24 @@ inline QualType Sema::CheckLogicalOperands( // C99 6.5.[13,14] (Result.Val.getInt() != 0 && Result.Val.getInt() != 1)) { Diag(Loc, diag::warn_logical_instead_of_bitwise) << rex.get()->getSourceRange() - << (Opc == BO_LAnd ? "&&" : "||") - << (Opc == BO_LAnd ? "&" : "|"); - } + << (Opc == BO_LAnd ? "&&" : "||"); + // Suggest replacing the logical operator with the bitwise version + Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator) + << (Opc == BO_LAnd ? "&" : "|") + << FixItHint::CreateReplacement(SourceRange( + Loc, Lexer::getLocForEndOfToken(Loc, 0, getSourceManager(), + getLangOptions())), + Opc == BO_LAnd ? "&" : "|"); + if (Opc == BO_LAnd) + // Suggest replacing "Foo() && kNonZero" with "Foo()" + Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant) + << FixItHint::CreateRemoval( + SourceRange( + Lexer::getLocForEndOfToken(lex.get()->getLocEnd(), + 0, getSourceManager(), + getLangOptions()), + rex.get()->getLocEnd())); + } } if (!Context.getLangOptions().CPlusPlus) { |