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

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.

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