]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/format/sentinel-1.c
e1e127dca38e9dcc1836e1290b978906a7ecbc8c
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / format / sentinel-1.c
1 /* Test for attribute sentinel. */
2 /* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
3 /* { dg-do compile } */
4 /* { dg-options "-Wformat" } */
5
6 #include <stddef.h> /* For NULL, which must be (ptr)0. */
7
8 extern int execl (const char *, const char *, ...);
9 extern int execlp (const char *, const char *, ...);
10
11 #define ATTR __attribute__ ((__sentinel__))
12
13 extern int a ATTR; /* { dg-warning "applies to function types" "sentinel" } */
14
15 extern void foo1 (const char *, ...) ATTR;
16 extern void foo2 (...) ATTR; /* { dg-error "ISO C requires|named arguments" "sentinel" } */
17 extern void foo3 () ATTR; /* { dg-warning "named arguments" "sentinel" } */
18 extern void foo4 (const char *, int) ATTR; /* { dg-warning "variadic functions" "sentinel" } */
19
20 extern void bar(void)
21 {
22 foo1 (); /* { dg-error "missing sentinel|too few arguments" "sentinel" } */
23 foo1 ("a"); /* { dg-warning "missing sentinel" "sentinel" } */
24 foo1 ("a", 1); /* { dg-warning "missing sentinel" "sentinel" } */
25 foo1 ("a", 0); /* { dg-warning "missing sentinel" "sentinel" } */
26 foo1 ("a", (void*)1); /* { dg-warning "missing sentinel" "sentinel" } */
27 foo1 ("a", NULL, 1); /* { dg-warning "missing sentinel" "sentinel" } */
28 foo1 ("a", NULL);
29
30 execl ("/bin/ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
31 execl ("/bin/ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
32 execl ("/bin/ls", "-aFC", NULL);
33
34 execlp ("ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
35 execlp ("ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
36 execlp ("ls", "-aFC", NULL);
37 }