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

--- Comment #42 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Szőts Ákos from comment #41)
> A newer example:
> 
> int main() {
>   bool exists = true;
>   int i = 0;
>   int sum = 0;
> 
>   volatile int array_size = 7;
>   volatile int array[7];
> 
>   while (exists)
>   {
>     for (i = 0; i < array_size - 1; i++)
>     {
>       if (array[i] == 0) sum += array[i + 1];
>       exists = false;
>     }
>   }
> 
>   return 0;
> }
> 
> Can be reproduced both by v5.3.0 and v6.1.1 with "g++ -O3 -Wall main.cpp".

Isn't this warning valid?  By marking array_size as volatile you are telling
the compiler that its value could change at any time.  So the loop won't
necessarily terminate once i == 6.

Reply via email to