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]
Other format: [Raw text]

Re: [Bug c/7776] const char* p = "foo"; if (p == "foo") ... iscompiled without warning!

On Sun, 25 May 2003, Falk Hueffner wrote:

> Seems like a reasonable idea to me; I don't see any legitimate reasons
> for comparisons with string literals. How about something like this?

E.g., an optimised string function macro that first compares the pointers
(which might be to string constants) before looking at contents only if
necessary.  glibc headers have contained funny expressions that expect 
multiple copies of a string constant argument to be the same, and 
differences such as &"foo"[1] - "foo" to be folded, if not actually 
evaluating "foo" == "foo".  If you know that the implementation merges 
identical string literals, this is a reasonable thing to do.

I don't believe this should be a mandatory warning - in general those (as 
opposed to mandatory pedwarns) should be avoided; a warning within -Wall 
would be the natural place, except that the possibility of this arising in 
conjunction with macros may mean -W is more appropriate.

Joseph S. Myers

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