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: "imitrichev at muctr dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 02 Mar 2016 16:51:31 +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
imitrichev <imitrichev at muctr dot ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |imitrichev at muctr dot ru
--- Comment #6 from imitrichev <imitrichev at muctr dot ru> ---
I think, while patching one should consider also warn on `for` loop empty body.
Whilst we can write something like
int i=0;
for (; i<5; a[i]=10, i++);
it is assumed to be not a great programming style.
int main()
{
for (; 1<2; );
if (1==1);
while (1==1);
return 0;
}
Now it warns only on `if` loop:
g++ empty.cpp -Wempty-body -o empty.out
empty.cpp: In function "int main()":
empty.cpp:4:10: warning: suggest braces around empty body in an Âif statement
[-Wempty-body]
It is really would be helpful to detect infinite loops caused by odd ';' after
`for` and `while` without debugger.