2015-10-17 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / c-c++-common / nonnull-1.c
blobb5c3d7f8866a9f7264f9876b329c7b0ed75c431b
1 /* Test for the bad usage of "nonnull" function attribute parms. */
2 /* */
3 /* { dg-do compile } */
4 /* { dg-options "-Wnonnull" } */
6 #include <stddef.h>
7 #include <stdlib.h>
9 void foo(void *bar) __attribute__((nonnull(1)));
11 void foo(void *bar) { if (!bar) abort(); } /* { dg-warning "nonnull argument" "bar compared to NULL" } */
13 extern int func (char *, char *, char *, char *) __attribute__((nonnull));
15 int
16 func (char *cp1, char *cp2, char *cp3, char *cp4)
18 if (cp1) /* { dg-warning "nonnull argument" "cp1 compared to NULL" } */
19 return 1;
21 if (cp2 == NULL) /* { dg-warning "nonnull argument" "cp2 compared to NULL" } */
22 return 2;
24 if (NULL != cp3) /* { dg-warning "nonnull argument" "cp3 compared to NULL" } */
25 return 3;
27 return (cp4 != 0) ? 0 : 1; /* { dg-warning "nonnull argument" "cp4 compared to NULL" } */