* builtin-attrs.def (ATTR_NOTHROW_SENTINEL_1): New.
[official-gcc.git] / gcc / testsuite / gcc.dg / format / sentinel-1.c
blob12915b7dc5a3a8cb0524c9dae60a1ad11845e5db
1 /* Test for attribute sentinel. */
2 /* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
3 /* { dg-do compile } */
4 /* { dg-options "-Wformat" } */
6 #include <stddef.h> /* For NULL, which must be (ptr)0. */
8 extern int execl (const char *, const char *, ...);
9 extern int execlp (const char *, const char *, ...);
10 extern int execle (const char *, const char *, ...);
11 extern char *envp[];
13 #define ATTR __attribute__ ((__sentinel__))
15 extern int a ATTR; /* { dg-warning "applies to function types" "sentinel" } */
17 extern void foo1 (const char *, ...) ATTR;
18 extern void foo2 (...) ATTR; /* { dg-error "ISO C requires|named arguments" "sentinel" } */
19 extern void foo3 () ATTR; /* { dg-warning "named arguments" "sentinel" } */
20 extern void foo4 (const char *, int) ATTR; /* { dg-warning "variadic functions" "sentinel" } */
21 extern void foo5 (const char *, ...) __attribute__ ((__sentinel__(1)));
22 extern void foo6 (const char *, ...) __attribute__ ((__sentinel__(5)));
23 extern void foo7 (const char *, ...) __attribute__ ((__sentinel__(0)));
24 extern void foo8 (const char *, ...) __attribute__ ((__sentinel__("a"))); /* { dg-warning "not an integer constant" "sentinel" } */
25 extern void foo9 (const char *, ...) __attribute__ ((__sentinel__(-1))); /* { dg-warning "less than zero" "sentinel" } */
26 extern void foo10 (const char *, ...) __attribute__ ((__sentinel__(1,3))); /* { dg-error "wrong number of arguments" "sentinel" } */
28 extern void bar(void)
30 foo1 (); /* { dg-error "missing sentinel|too few arguments" "sentinel" } */
31 foo1 ("a"); /* { dg-warning "missing sentinel" "sentinel" } */
32 foo1 ("a", 1); /* { dg-warning "missing sentinel" "sentinel" } */
33 foo1 ("a", 0); /* { dg-warning "missing sentinel" "sentinel" } */
34 foo1 ("a", (void*)1); /* { dg-warning "missing sentinel" "sentinel" } */
35 foo1 ("a", NULL, 1); /* { dg-warning "missing sentinel" "sentinel" } */
36 foo1 ("a", NULL);
38 foo5 ("a", 1, 2, 3, NULL); /* { dg-warning "missing sentinel" "sentinel" } */
39 foo5 ("a", 1, 2, NULL, 3);
40 foo5 ("a", 1, NULL, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
41 foo5 ("a", NULL, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
42 foo5 ("a", 0, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
44 foo6 ("a", 1, NULL); /* { dg-warning "not enough arguments" "sentinel" } */
45 foo6 ("a", 1, NULL, 2); /* { dg-warning "not enough arguments" "sentinel" } */
46 foo6 ("a", 1, NULL, 2, 3); /* { dg-warning "not enough arguments" "sentinel" } */
47 foo6 ("a", NULL, 1, 2, 3); /* { dg-warning "not enough arguments" "sentinel" } */
48 foo6 ("a", NULL, 1, 2, 3, 4); /* { dg-warning "missing sentinel" "sentinel" } */
49 foo6 ("a", NULL, 1, 2, 3, 4, 5);
50 foo6 ("a", 0, 1, 2, 3, 4, 5); /* { dg-warning "missing sentinel" "sentinel" } */
51 foo6 ("a", NULL, 1, 2, 3, 4, 5, 6); /* { dg-warning "missing sentinel" "sentinel" } */
53 foo7 ("a", 1, 2, 3, NULL);
55 execl ("/bin/ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
56 execl ("/bin/ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
57 execl ("/bin/ls", "-aFC", NULL);
59 execlp ("ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
60 execlp ("ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
61 execlp ("ls", "-aFC", NULL);
63 execle ("ls", "-aFC", ".", envp); /* { dg-warning "missing sentinel" "sentinel" } */
64 execle ("ls", "-aFC", ".", 0, envp); /* { dg-warning "missing sentinel" "sentinel" } */
65 execle ("ls", "-aFC", ".", NULL, envp);