summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-04 19:56:47 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2005-12-04 19:56:47 +0000
commit19f0596c4a5e1a38ec4e960f475f89dab547665d (patch)
tree0c868f77e7b841472e04bdb16256459255a05c04 /gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c
parent4a72b87684934abf9883bb0a90f0f3cb7329b659 (diff)
downloadgcc-19f0596c4a5e1a38ec4e960f475f89dab547665d.tar.gz
PR c/7776
* common.opt (Wstring-literal-comparison): New command line option. * c-opts.c (c_common_handle_option): Set it with -Wall. * c-typeck.c (parser_build_binary_op): Issue warning if either operand of a comparison operator is a string literal, except for testing equality or inequality against NULL. * doc/invoke.texi: Document new -Wstring-literal-comparison option. * gcc.dg/Wstring-literal-comparison-1.c: New test case. * gcc.dg/Wstring-literal-comparison-2.c: Likewise. * gcc.dg/Wstring-literal-comparison-3.c: Likewise. * gcc.dg/Wstring-literal-comparison-4.c: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@108018 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c b/gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c
new file mode 100644
index 00000000000..c5dea463b51
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c
@@ -0,0 +1,29 @@
+/* PR c/7776 */
+/* { dg-do compile } */
+/* { dg-options "-Wstring-literal-comparison" } */
+
+int test1(char *ptr)
+{
+ return ptr == "foo"; /* { dg-warning "comparison with string" } */
+}
+
+int test2()
+{
+ return "foo" != (const char*)0;
+}
+
+int test3()
+{
+ return "foo" == (const char*)0;
+}
+
+int test4()
+{
+ return (const char*)0 != "foo";
+}
+
+int test5()
+{
+ return (const char*)0 == "foo";
+}
+