[Bug c/7776] const char* p = "foo"; if (p == "foo") ... is compiled without warning!
jsm28@cam.ac.uk
gcc-bugzilla@gcc.gnu.org
Sun May 25 01:49:00 GMT 2003
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7776
------- Additional Comments From jsm28@cam.ac.uk 2003-05-25 01:29 -------
Subject: Re: [Bug c/7776] const char* p = "foo"; if (p == "foo") ... is
compiled 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.
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
More information about the Gcc-bugs
mailing list