This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/62184] [C/C++] Extend -Wempty-body to 'while' loops


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]