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

Peter Damianov <peter0x44 at disroot dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter0x44 at disroot dot org

--- Comment #2 from Peter Damianov <peter0x44 at disroot dot org> ---
For the following case that I saw out in the wild, someone wrote something
like:

bool x;
bool func(void)
{
  return x;
}

int main(void)
{
   while (!func) {}
}


which emitted a very poorly worded run-on sentence:

test.c:10:15: warning: the comparison will always evaluate as 'true' for the
address of 'func' will never be NULL [-Waddress]
   10 |         while(!func) {}
      |               ^

"for the" probably ought to be "because the"
and there isn't really an explicitly written comparison there to begin with


If I remove the !, this gets emitted instead:

test.c:9:16: warning: the address of 'func' will always evaluate as 'true'
[-Waddress]
    9 |         while (func) {}
      |                ^~~~

which is also lacking the suggestion for parenthesis.

For comparison, clang emits these two warnings:

test.c:9:9: warning: address of function 'func' will always evaluate to 'true'
[-Wpointer-bool-conversion]
    9 |         while (func) {}
      |         ~~~~~  ^~~~
test.c:9:9: note: prefix with the address-of operator to silence this warning
    9 |         while (func) {}
      |                ^
      |                &
test.c:9:9: note: suffix with parentheses to turn this into a function call
    9 |         while (func) {}
      |                ^
      |                    ()
test.c:10:10: warning: address of function 'func' will always evaluate to
'true' [-Wpointer-bool-conversion]
   10 |         while (!func) {}
      |                ~^~~~
test.c:10:10: note: prefix with the address-of operator to silence this warning
   10 |         while (!func) {}
      |                 ^
      |                 &
test.c:10:10: note: suffix with parentheses to turn this into a function call
   10 |         while (!func) {}
      |                 ^
      |                     ()


Which has a suggestion to either write address-of, or insert the parenthesis.

Reply via email to