summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/format/sentinel-1.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.dg/format/sentinel-1.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.dg/format/sentinel-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/format/sentinel-1.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/format/sentinel-1.c b/gcc/testsuite/gcc.dg/format/sentinel-1.c
new file mode 100644
index 000000000..0c8a2ac77
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/sentinel-1.c
@@ -0,0 +1,73 @@
+/* Test for attribute sentinel. */
+/* Origin: Kaveh Ghazi <ghazi@caip.rutgers.edu> */
+/* { dg-do compile } */
+/* { dg-options "-Wformat" } */
+
+#include <stddef.h> /* For NULL, which must be (ptr)0. */
+
+extern int execl (const char *, const char *, ...);
+extern int execlp (const char *, const char *, ...);
+extern int execle (const char *, const char *, ...);
+extern char *envp[];
+
+#define ATTR __attribute__ ((__sentinel__))
+
+extern int a ATTR; /* { dg-warning "applies to function types" "sentinel" } */
+
+extern void foo1 (const char *, ...) ATTR; /* { dg-message "note: declared here" } */
+extern void foo2 (...) ATTR; /* { dg-error "ISO C requires|named arguments" "sentinel" } */
+extern void foo3 () ATTR; /* { dg-warning "named arguments" "sentinel" } */
+extern void foo4 (const char *, int) ATTR; /* { dg-warning "variadic functions" "sentinel" } */
+extern void foo5 (const char *, ...) __attribute__ ((__sentinel__(1)));
+extern void foo6 (const char *, ...) __attribute__ ((__sentinel__(5)));
+extern void foo7 (const char *, ...) __attribute__ ((__sentinel__(0)));
+extern void foo8 (const char *, ...) __attribute__ ((__sentinel__("a"))); /* { dg-warning "not an integer constant" "sentinel" } */
+extern void foo9 (const char *, ...) __attribute__ ((__sentinel__(-1))); /* { dg-warning "less than zero" "sentinel" } */
+extern void foo10 (const char *, ...) __attribute__ ((__sentinel__(1,3))); /* { dg-error "wrong number of arguments" "sentinel" } */
+
+extern void bar(void)
+{
+ foo1 (); /* { dg-error "not enough|too few arguments" "sentinel" } */
+ foo1 (NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo1 ("a"); /* { dg-warning "not enough" "sentinel" } */
+ foo1 ("a", 1); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo1 ("a", 0); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo1 ("a", (void*)1); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo1 ("a", NULL, 1); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo1 ("a", NULL);
+
+ foo5 (NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo5 (NULL, 1); /* { dg-warning "not enough" "sentinel" } */
+ foo5 ("a", NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo5 ("a", NULL, 1);
+ foo5 ("a", 1, 2, 3, NULL); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo5 ("a", 1, 2, NULL, 3);
+ foo5 ("a", 1, NULL, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo5 ("a", NULL, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo5 ("a", 0, 1, 2, 3); /* { dg-warning "missing sentinel" "sentinel" } */
+
+ foo6 ("a", 1, NULL); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", 1, NULL, 2); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", 1, NULL, 2, 3); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", NULL, 1, 2, 3); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", NULL, 1, 2, 3, 4); /* { dg-warning "not enough" "sentinel" } */
+ foo6 (NULL, 1, 2, 3, 4, 5); /* { dg-warning "not enough" "sentinel" } */
+ foo6 ("a", NULL, 1, 2, 3, 4, 5);
+ foo6 ("a", 0, NULL, 1, 2, 3, 4, 5);
+ foo6 ("a", 0, 1, 2, 3, 4, 5); /* { dg-warning "missing sentinel" "sentinel" } */
+ foo6 ("a", NULL, 1, 2, 3, 4, 5, 6); /* { dg-warning "missing sentinel" "sentinel" } */
+
+ foo7 ("a", 1, 2, 3, NULL);
+
+ execl ("/bin/ls", "/bin/ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
+ execl ("/bin/ls", "/bin/ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
+ execl ("/bin/ls", "/bin/ls", "-aFC", NULL);
+
+ execlp ("ls", "ls", "-aFC"); /* { dg-warning "missing sentinel" "sentinel" } */
+ execlp ("ls", "ls", "-aFC", 0); /* { dg-warning "missing sentinel" "sentinel" } */
+ execlp ("ls", "ls", "-aFC", NULL);
+
+ execle ("ls", "ls", "-aFC", ".", envp); /* { dg-warning "missing sentinel" "sentinel" } */
+ execle ("ls", "ls", "-aFC", ".", 0, envp); /* { dg-warning "missing sentinel" "sentinel" } */
+ execle ("ls", "ls", "-aFC", ".", NULL, envp);
+}