This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33925] gcc -Waddress lost some useful warnings
- From: "mec at google dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Jul 2009 16:04:44 -0000
- Subject: [Bug c++/33925] gcc -Waddress lost some useful warnings
- References: <bug-33925-11211@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from mec at google dot com 2009-07-31 16:04 -------
Subject: Re: gcc -Waddress lost some useful warnings
Yes, I think this is a bug, because the behavior of gcc doesn't match
its documentation.
First, I think the C++ standard forbids a function from having a null
address:
[conv.ptr] 4.10 -1- A null pointer constant is an integral constant
expression (5.19) rvalue of integer type that evalutes to zero. A null
pointer constant can be converted to a pointer type; the result is the
null pointer value of that type and is distinguishable from every other
value of pointer to object or pointer to function type.
Even if you break this to allow for weak pointers to functions, the
documentation for -Waddress says:
http://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Warning-Options.html#Warning-Options
"Warn about suspicious uses of memory addresses. These include the
address of a function in a conditional expression such as void
func(void); if (func) ... such uses typically indicate a programmer
error: the address of a function always evaluates to true, so their use
in a conditional usually indicate that the programmer forgot the
parentheses in a function call ...".
This documentation repeats the claim that "the address of a function is
always true".
More than that: "warnings are diagnostic messages that report
constructions which are not inherently erroneous but which are risky or
suggest there may have been an error". By enabling -Waddress, I believe
the user intends to report all instances of "if (func)" with the
expectation that most of them are mistaken versions of "if (func())" or
"if (func(some_parameters ...))". If the user is building
(non-standard) code where the addresses of some functions may be null
and "if (func)" is likely the intended meaning, then they can decline to
turn on -Waddress. If such code is common, you may want to re-think the
inclusion of -Waddress in -Wall.
As it is, -Waddress sometimes prints the message that it is documented
to print, and sometimes does not.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33925