This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/62184] [C/C++] Extend -Wempty-body to 'while' loops
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 19 Aug 2014 09:52:59 +0000
- Subject: [Bug c/62184] [C/C++] Extend -Wempty-body to 'while' loops
- Auto-submitted: auto-generated
- References: <bug-62184-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62184
Tobias Burnus <burnus at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
CC| |mpolacek at gcc dot gnu.org
Summary|[C/C++] Extend -Wempty-body |[C/C++] Extend -Wempty-body
|to |to 'while' loops
--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> ---
For an empty "if" loop, GCC warns with -Wextra:
foo.cc:5:13: warning: suggest braces around empty body in an âifâ statement
[-Wempty-body]
if (bar());
^
However, using a "while" loop, it doesn't. Clang warns (by default) in that
case:
foo.cc:5:16: warning: while loop has empty body [-Wempty-body]
while (bar());
^
foo.cc:5:16: note: put the semicolon on a separate line to silence this warning
Again, I found that issue in a real-world code.
Test case:
int bar ();
void sleep();
int foo() {
while (bar());
sleep();
return 1;
}