PR c/47931 - missing -Waddress warning for comparison with NULL
authorMartin Sebor <msebor@redhat.com>
Wed, 11 Jan 2017 18:33:13 +0000 (18:33 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Wed, 11 Jan 2017 18:33:13 +0000 (11:33 -0700)
gcc/testsuite/ChangeLog:
* c-c++-common/Waddress-2.c: New test.

From-SVN: r244331

gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Waddress-2.c [new file with mode: 0644]

index 4df8d41da99fdf1aa64d2958d12e1e81f1296792..51bcf982f6d060de1171e1d227bd070cdcd0b59b 100644 (file)
@@ -1,3 +1,8 @@
+2017-01-11  Martin Sebor  <msebor@redhat.com>
+
+       PR c/47931
+       * c-c++-common/Waddress-2.c: New test.
+
 2017-01-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/78341
diff --git a/gcc/testsuite/c-c++-common/Waddress-2.c b/gcc/testsuite/c-c++-common/Waddress-2.c
new file mode 100644 (file)
index 0000000..b58a55f
--- /dev/null
@@ -0,0 +1,30 @@
+/* PR c/47931 - missing -Waddress warning for comparison with NULL
+  { dg-do compile }
+  { dg-options "-Waddress" } */
+
+#define NULL ((void *) 0)
+
+int i;
+
+int f0 (void)
+{
+  return &i != 0;   /* { dg-warning "the address of .i. will never be NULL" } */
+}
+
+int f1 (void)
+{
+  return &i != (void *) 0;   /* { dg-warning "the address of .i. will never be NULL" } */
+}
+
+int f2 (void)
+{
+  return &i != NULL;   /* { dg-warning "the address of .i. will never be NULL" } */
+}
+
+int f3 (void)
+{
+  return &i != (int *) 0;
+}
+
+
+