This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/7776] const char* p = "foo"; if (p == "foo") ... is compiled without warning!
- From: "trt at acm dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Jun 2005 15:48:56 -0000
- Subject: [Bug middle-end/7776] const char* p = "foo"; if (p == "foo") ... is compiled without warning!
- References: <20020830090600.7776.udbz@rz.uni-karlsruhe.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From trt at acm dot org 2005-06-06 15:48 -------
I recommend a version with fewer false positives.
I've been using a warning like this for years, with zero false positives.
The current gcc-4-ified version is:
- /* check for comparing string constant with anything besides simple zero */
- if (TREE_CODE_CLASS (code) == tcc_comparison && extra_warnings
- && (code1 == STRING_CST) != (code2 == STRING_CST)
- && !integer_zerop (arg1.value) && !integer_zerop (arg2.value))
- warning (0, "comparison of pointer with string literal");
An older suggestion is http://gcc.gnu.org/ml/gcc-patches/1999-10n/msg00548.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7776