diff options
| author | Reid Kleckner <rnk@google.com> | 2017-11-17 21:33:28 +0000 |
|---|---|---|
| committer | Reid Kleckner <rnk@google.com> | 2017-11-17 21:33:28 +0000 |
| commit | c0a81071d3d89c4e07f0ef39f5bb96eb9e6df76b (patch) | |
| tree | 4f333696109dc564b84c0a320134b0642cd9d283 /clang/lib | |
| parent | 188efda585f1da5ab91eedfe75a292bf6b6fd803 (diff) | |
| download | bcm5719-llvm-c0a81071d3d89c4e07f0ef39f5bb96eb9e6df76b.tar.gz bcm5719-llvm-c0a81071d3d89c4e07f0ef39f5bb96eb9e6df76b.zip | |
Loosen -Wempty-body warning
Do not show it when `if` or `else` come from macros.
E.g.,
#define USED(A) if (A); else
#define SOME_IF(A) if (A)
void test() {
// No warnings are shown in those cases now.
USED(0);
SOME_IF(0);
}
Patch by Ilya Biryukov!
Differential Revision: https://reviews.llvm.org/D40185
llvm-svn: 318556
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Parse/ParseStmt.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 3 |
3 files changed, 3 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index e8cf7d5fa45..ec14cee5a34 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -1101,6 +1101,7 @@ bool Parser::ParseParenExprOrCondition(StmtResult *InitStmt, // Otherwise the condition is valid or the rparen is present. T.consumeClose(); + Cond.setRParenLoc(T.getCloseLocation()); // Check for extraneous ')'s to catch things like "if (foo())) {". We know // that all callers are looking for a statement after the condition, so ")" diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index e662a5c8b97..8a85830bfdb 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -11821,7 +11821,7 @@ static bool ShouldDiagnoseEmptyStmtBody(const SourceManager &SourceMgr, // Get line numbers of statement and body. bool StmtLineInvalid; - unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc, + unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc, &StmtLineInvalid); if (StmtLineInvalid) return false; diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 07b70305c19..de9b8c3b76c 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -530,8 +530,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt, if (elseStmt) DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body); else - DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt, - diag::warn_empty_if_body); + DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body); return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc, elseStmt); |

