2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / gcc.dg / nonnull-1.c
blob51a8a3373ee12bee58ff771a9c39996c1eee6282
1 /* Test for the "nonnull" function attribute. */
2 /* Origin: Jason Thorpe <thorpej@wasabisystems.com> */
3 /* { dg-do compile } */
4 /* { dg-options "-Wnonnull" } */
6 #include <stddef.h>
8 extern void func1 (char *, char *, int) __attribute__((nonnull));
10 extern void func2 (char *, char *) __attribute__((nonnull(1)));
12 extern void func3 (char *, int, char *, int)
13 __attribute__((nonnull(1,3)));
15 extern void func4 (char *, char *) __attribute__((nonnull(1)))
16 __attribute__((nonnull(2)));
18 void
19 foo (int i1, int i2, int i3, char *cp1, char *cp2, char *cp3)
21 func1(cp1, cp2, i1);
23 func1(NULL, cp2, i1); /* { dg-warning "null" "null with argless nonnull 1" } */
24 func1(cp1, NULL, i1); /* { dg-warning "null" "null with argless nonnull 2" } */
25 func1(cp1, cp2, 0);
27 func2(cp1, NULL);
28 func2(NULL, cp1); /* { dg-warning "null" "null with single explicit nonnull" } */
30 func3(NULL, i2, cp3, i3); /* { dg-warning "null" "null with explicit nonnull 1" } */
31 func3(cp3, i2, NULL, i3); /* { dg-warning "null" "null with explicit nonnull 3" } */
33 func1(i1 ? cp1 : NULL, cp2, i3); /* { dg-warning "null" "null with cond expr rhs" } */
34 func1(i1 ? NULL : cp1, cp2, i3); /* { dg-warning "null" "null with cond expr lhs" } */
35 func1(i1 ? (i2 ? cp1 : NULL) : cp2, cp3, i3); /* { dg-warning "null" "null with nested cond expr" } */
37 func4(NULL, cp1); /* { dg-warning "null" "null with multiple attributes 1" } */
38 func4(cp1, NULL); /* { dg-warning "null" "null with multiple attributes 2" } */