[Bug c/62184] [C/C++] Extend -Wempty-body to 'while' loops
manu at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Nov 12 15:26:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62184
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-11-12
Ever confirmed|0 |1
--- Comment #4 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
I'm going to confirm this. We definitely want this. The heuristic of Clang
seems quite elaborated: only warn when the ';' is on the same line and there is
a statement after it that starts at a higher column than the while.line.
void foo ()
{
#define EMPTY
while (0)EMPTY;
foo(); // warns if preprocessed
while (0);
foo(); // warns
while (0);
foo(); // does not warn
while (0); // does not warn
}
$ clang test.c
test.c:6:12: warning: while loop has empty body [-Wempty-body]
while (0);
^
test.c:6:12: note: put the semicolon on a separate line to silence this warning
$ clang test.c -save-temps
In file included from test.c:1:
test.c:4:12: warning: while loop has empty body [-Wempty-body]
while (0);
^
test.c:4:12: note: put the semicolon on a separate line to silence this warning
test.c:6:12: warning: while loop has empty body [-Wempty-body]
while (0);
^
test.c:6:12: note: put the semicolon on a separate line to silence this warning
More information about the Gcc-bugs
mailing list