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 == "")

Joe Buck wrote:
> > 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".

I will help out in this case of leak of imagination:

 void gui_paned_menu_callback_function(Widget *w)

	char *label;
        label = gui_get_the_label(w);
	if (label == "BANG")

 int main(int argc, char *argv[]) 
	Widget *item;
	item = create_menu_item("BANG");
        add_callback(item, gui_paned_menu_callback_function);

Perfectly valid C and makes perfect sense on platforms which collate
constant strings. 

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

--Marcin Dalecki

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