This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C: Proposal: Warning using char* a; if(a == "")
- To: jbuck at synopsys dot com (Joe Buck)
- Subject: Re: C: Proposal: Warning using char* a; if(a == "")
- From: Joe Buck <jbuck at synopsys dot COM>
- Date: Fri, 5 Nov 99 9:31:07 PST
- Cc: gcc at gcc dot gnu dot org
> So, I do think that the warning makes sense. A logical place to put
> the warning would be in the truthvalue_conversion function.
I see that there is already a proposed patch,
http://egcs.cygnus.com/ml/gcc-patches/1999-10/msg00548.html
Doing it in truthvalue_conversion would enable it for C, C++ and
Objective-C, while doing it in c-typeck means it has to be done
again for C++. I think that it's needed more in C++ than in C.
As for Andrew Morton's warning against adding new warnings: in this
particular case, if this patch caused a new warning, the users'
code is almost certainly broken: I can't think of any programs
where a direct comparison to the string literal can have a
deterministic result that is not "always true" or "always false".
My criterion for adding a new -Wall warning is as follows: are there
useful programs where the warning cannot be suppressed without making the
code worse, or making the programmer work hard? Or does it "cry wolf" a
lot? If either are true, it doesn't go in -Wall. If not, and the warning
is likely to catch errors, it does go in -Wall.