[Bug c/7776] const char* p = "foo"; if (p == "foo") ... is compiled without warning!
Richard Kenner
kenner@vlsi1.ultra.nyu.edu
Sun May 25 06:31:00 GMT 2003
--- 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".
More information about the Gcc-patches
mailing list