diff options
author | Roger Sayle <roger@eyesopen.com> | 2005-12-04 19:56:47 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2005-12-04 19:56:47 +0000 |
commit | e994a705a9d8447c17486c13d741c2692c475f67 (patch) | |
tree | 0c868f77e7b841472e04bdb16256459255a05c04 /gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c | |
parent | 93af36c5c18bae3a294d98e46300ea3a867ecf56 (diff) | |
download | gcc-e994a705a9d8447c17486c13d741c2692c475f67.tar.gz |
re PR c/7776 (const char* p = "foo"; if (p == "foo") ... is compiled without warning!)
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.
From-SVN: r108018
Diffstat (limited to 'gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/Wstring-literal-comparison-1.c | 29 |
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"; +} + |