This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C: Proposal: Warning using char* a; if(a == "")

> 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,

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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]