PR middle-end/85602 - -Wsizeof-pointer-memaccess for strncat with size of source
[official-gcc.git] / gcc / testsuite / c-c++-common / nonnull-1.c
blob2446d6fbcfa65b177f69e746ac30333998e263ab
1 /* Test for the bad usage of "nonnull" function attribute parms. */
2 /* */
3 /* { dg-do compile } */
4 /* { dg-options "-Wnonnull-compare" } */
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" } */
30 __attribute__((nonnull (1))) int
31 func2 (char *cp)
33 return (cp != NULL) ? 1 : 0; /* { dg-warning "nonnull argument" "cp compared to NULL" { xfail c++ } } */