[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc-bugs
Subject:    [Bug c/53871] Please warn about endless loops if they are obvious
From:       "dcb314 at hotmail dot com" <gcc-bugzilla () gcc ! gnu ! org>
Date:       2015-12-30 21:07:50
Message-ID: bug-53871-4-yKtcjxaZIN () http ! gcc ! gnu ! org/bugzilla/
[Download RAW message or body]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53871

--- Comment #8 from David Binderman <dcb314 at hotmail dot com> ---
(In reply to Andrew Pinski from comment #7)
> The above loop is not so obvious an infinite loop at all.  Since f2 is not
> declared as pure/const, GCC can think the return value changes without the
> argument changing.  So the example in comment #6 is not an obvious example
> :).

I took out the if statement and gcc still can't detect the problem

void f3()
{
        int i = 0;

        do {
                int n = f2( i);
        } while (i < 8);
}

$ ~/gcc/results/bin/gcc -c -O2 -Wall -Wextra dec30b.cc
dec30b.cc: In function ‘void f3()':
dec30b.cc:23:7: warning: unused variable ‘n' [-Wunused-variable]
   int n = f2( i);
       ^
$ 

On the other hand, here is cppcheck detecting the problem:

[dec30b.cc:24]: (style) Condition 'i<8' is always true=
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic