Hi,
This patch fixes bug 19785 and adds a new test case for the problem.
https://llvm.org/bugs/show_bug.cgi?id=19785
In a case like:
if ( ptr == NULL );
the check used to consider the definition location of NULL, instead of the
current line.
(This is the first time I am attaching a patch, please inform me if I do
something wrong)
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index c4ff8b4..5eafa50 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -8625,7 +8625,7 @@ bool ShouldDiagnoseEmptyStmtBody(const SourceManager &SourceMgr,
// Get line numbers of statement and body.
bool StmtLineInvalid;
- unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
+ unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
&StmtLineInvalid);
if (StmtLineInvalid)
return false;
diff --git a/test/SemaCXX/warn-empty-body.cpp b/test/SemaCXX/warn-empty-body.cpp
index d3aaac1..f1bbd5a 100644
--- a/test/SemaCXX/warn-empty-body.cpp
+++ b/test/SemaCXX/warn-empty-body.cpp
@@ -3,11 +3,14 @@
void a(int i);
int b();
int c();
-
+#define NULL_DEF 0
void test1(int x, int y) {
while(true) {
if (x); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
+ int *ptr = NULL_DEF;
+ if (ptr == NULL_DEF); // expected-warning {{if statement has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
+
int i;
// PR11329
for (i = 0; i < x; i++); { // expected-warning{{for loop has empty body}} expected-note{{put the semicolon on a separate line to silence this warning}}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits