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

--- Comment #4 from Peter Damianov <peter0x44 at disroot dot org> ---
I noticed that we don't support suppressing the warning with & as clang
suggests.

void func();

int main() {
  if (func) {}
  if (&func) {}
}
with clang:

/tmp/test_addr.cpp:4:7: warning: address of function 'func' will always
evaluate to 'true'
      [-Wpointer-bool-conversion]
    4 |   if (func) {}
      |   ~~  ^~~~
/tmp/test_explicit_addr.cpp:4:7: note: prefix with the address-of operator to
silence this warning
    4 |   if (func) {}
      |       ^
      |       &
1 warning generated.

no warning on the second if

but with gcc, both instances warn:

/tmp/test_addr.cpp: In function ‘int main()’:
/tmp/test_addr.cpp:4:7: warning: the address of ‘void func()’ will never be
NULL [-Waddress]
    4 |   if (func) {}
      |       ^~~~
/tmp/test_addr.cpp:1:6: note: ‘void func()’ declared here
    1 | void func();
      |      ^~~~
/tmp/test_addr.cpp:5:7: warning: the address of ‘void func()’ will never be
NULL [-Waddress]
    5 |   if (&func) {}
      |       ^~~~~
/tmp/test_addr.cpp:1:6: note: ‘void func()’ declared here
    1 | void func();
      |      ^~~~

Reply via email to