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;
}

Reply via email to