This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug c/7776] const char* p = "foo"; if (p == "foo") ... is compiled without warning!
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- To: falk dot hueffner at student dot uni-tuebingen dot de
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 24 May 03 22:45:26 EDT
- Subject: Re: [Bug c/7776] const char* p = "foo"; if (p == "foo") ... is compiled without warning!
--- fold-const.c 23 May 2003 03:46:52 -0000 1.252
+++ fold-const.c 25 May 2003 00:56:19 -0000
+ /* Warn about things like if (str == "foo"). */
+ if ((code == EQ_EXPR || code == NE_EXPR)
+ && TREE_CODE (arg1) == ADDR_EXPR
+ && TREE_CODE (TREE_OPERAND (arg1, 0)) == STRING_CST)
+ warning("comparison with string literal");
+
Warning of this nature should be done when the tree is built, not when
its folded. Also, there needs to a blank after "warning".