This is the mail archive of the
mailing list for the GCC project.
Re: [Bug c/7776] const char* p = "foo"; if (p == "foo") ... iscompiled without warning!
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- Cc: gcc-bugzilla at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Sun, 25 May 2003 02:28:40 +0100 (BST)
- Subject: Re: [Bug c/7776] const char* p = "foo"; if (p == "foo") ... iscompiled without warning!
- References: <firstname.lastname@example.org><email@example.com>
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" - "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