[Bug c++/92375] New: Warn on suspicious taking of function address instead of calling a function
antoshkka at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Nov 5 10:58:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92375
Bug ID: 92375
Summary: Warn on suspicious taking of function address instead
of calling a function
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Keywords: diagnostic
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
Consider the simple example:
bool function();
bool test() {
bool result = function;
if (result) {
return 1;
} else {
return 2;
}
}
Students and scholars often forget to put braces to actually call the function.
Unfortunately GCC does not give a warning that is implemented in other
compilers:
<source>:4:19: warning: address of function 'function' will always evaluate to
'true' [-Wpointer-bool-conversion]
bool result = function;
~~~~~~ ^~~~~~~~
<source>:4:19: note: prefix with the address-of operator to silence this
warning
bool result = function;
^
&
<source>:4:19: note: suffix with parentheses to turn this into a function call
bool result = function;
^
()
Please, add a warning.
More information about the Gcc-bugs
mailing list