summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/format/strfmon-1.c
diff options
context:
space:
mode:
authorJoseph Myers <jsm28@cam.ac.uk>2001-01-06 18:47:19 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2001-01-06 18:47:19 +0000
commitcd5662732a9ce840e9276d18b080cd38ec1d66a5 (patch)
tree3fde55ebae06b1a7ecee2eaac788cb5c9478910f /gcc/testsuite/gcc.dg/format/strfmon-1.c
parentfa6f74f611d8d35e3d07ecf6fc40e7e07ff6792a (diff)
downloadgcc-cd5662732a9ce840e9276d18b080cd38ec1d66a5.tar.gz
format.exp: New file.
* gcc.dg/format/format.exp: New file. * gcc.dg/c90-printf-1.c: Rename to gcc.dg/format/c90-printf-1.c. * gcc.dg/c90-printf-2.c: Rename to gcc.dg/format/c90-printf-2.c. * gcc.dg/c90-printf-3.c: Rename to gcc.dg/format/c90-printf-3.c. * gcc.dg/c94-printf-1.c: Rename to gcc.dg/format/c94-printf-1.c. * gcc.dg/c99-printf-1.c: Rename to gcc.dg/format/c99-printf-1.c. * gcc.dg/c99-printf-2.c: Rename to gcc.dg/format/c99-printf-2.c. * gcc.dg/c99-printf-3.c: Rename to gcc.dg/format/c99-printf-3.c. * gcc.dg/c90-scanf-1.c: Rename to gcc.dg/format/c90-scanf-1.c. * gcc.dg/c90-scanf-2.c: Rename to gcc.dg/format/c90-scanf-2.c. * gcc.dg/c90-scanf-3.c: Rename to gcc.dg/format/c90-scanf-3.c. * gcc.dg/c90-scanf-4.c: Rename to gcc.dg/format/c90-scanf-4.c. * gcc.dg/c94-scanf-1.c: Rename to gcc.dg/format/c94-scanf-1.c. * gcc.dg/c99-scanf-1.c: Rename to gcc.dg/format/c99-scanf-1.c. * gcc.dg/c99-scanf-2.c: Rename to gcc.dg/format/c99-scanf-2.c. * gcc.dg/c99-scanf-3.c: Rename to gcc.dg/format/c99-scanf-3.c. * gcc.dg/c90-strftime-1.c: Rename to gcc.dg/format/c90-strftime-1.c. * gcc.dg/c90-strftime-2.c: Rename to gcc.dg/format/c90-strftime-2.c. * gcc.dg/c99-strftime-1.c: Rename to gcc.dg/format/c99-strftime-1.c. * gcc.dg/c99-strftime-2.c: Rename to gcc.dg/format/c99-strftime-2.c. * gcc.dg/format-array-1.c: Rename to gcc.dg/format/array-1.c. * gcc.dg/format-attr-1.c: Rename to gcc.dg/format/attr-1.c. * gcc.dg/format-branch-1.c: Rename to gcc.dg/format/branch-1.c. * gcc.dg/format-diag-1.c: Rename to gcc.dg/format/diag-1.c. * gcc.dg/format-errmk-1.c: Rename to gcc.dg/format/errmk-1.c. * gcc.dg/format-ext-1.c: Rename to gcc.dg/format/ext-1.c. * gcc.dg/format-ext-2.c: Rename to gcc.dg/format/ext-2.c. * gcc.dg/format-ext-3.c: Rename to gcc.dg/format/ext-3.c. * gcc.dg/format-ext-4.c: Rename to gcc.dg/format/ext-4.c. * gcc.dg/format-ext-5.c: Rename to gcc.dg/format/ext-5.c. * gcc.dg/format-miss-1.c: Rename to gcc.dg/format/miss-1.c. * gcc.dg/format-miss-2.c: Rename to gcc.dg/format/miss-2.c. * gcc.dg/format-no-exargs-1.c: Rename to gcc.dg/format/no-exargs-1.c. * gcc.dg/format-no-y2k-1.c: Rename to gcc.dg/format/no-y2k-1.c. * gcc.dg/format-nonlit-1.c: Rename to gcc.dg/format/nonlit-1.c. * gcc.dg/format-nonlit-2.c: Rename to gcc.dg/format/nonlit-2.c. * gcc.dg/format-nonlit-3.c: Rename to gcc.dg/format/nonlit-3.c. * gcc.dg/format-sec-1.c: Rename to gcc.dg/format/sec-1.c. * gcc.dg/format-strfmon-1.c: Rename to gcc.dg/format/strfmon-1.c. * gcc.dg/format-va-1.c: Rename to gcc.dg/format/va-1.c. * gcc.dg/format-warnll-1.c: Rename to gcc.dg/format/warnll-1.c. * gcc.dg/format-xopen-1.c: Rename to gcc.dg/format/xopen-1.c. * gcc.dg/formatz-1.c: Rename to gcc.dg/format/z-1.c. From-SVN: r38749
Diffstat (limited to 'gcc/testsuite/gcc.dg/format/strfmon-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/format/strfmon-1.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/format/strfmon-1.c b/gcc/testsuite/gcc.dg/format/strfmon-1.c
new file mode 100644
index 00000000000..40d44c14a71
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/strfmon-1.c
@@ -0,0 +1,68 @@
+/* Test for strfmon format checking. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+/* Kludge to get something that may be ssize_t. */
+#define unsigned signed
+typedef __SIZE_TYPE__ ssize_t;
+#undef unsigned
+
+#define NULL ((void *)0)
+
+extern ssize_t strfmon (char *restrict, size_t, const char *restrict, ...);
+
+void
+foo (char *s, size_t m, double d, long double ld)
+{
+ /* Examples of valid formats from Austin Group draft 5. */
+ strfmon (s, m, "%n", d);
+ strfmon (s, m, "%11n", d);
+ strfmon (s, m, "%#5n", d);
+ strfmon (s, m, "%=*#5n", d);
+ strfmon (s, m, "%=0#5n", d);
+ strfmon (s, m, "%^#5n", d);
+ strfmon (s, m, "%^#5.0n", d);
+ strfmon (s, m, "%^#5.4n", d);
+ strfmon (s, m, "%(#5n", d);
+ strfmon (s, m, "%(!#5n", d);
+ /* Some more valid formats, including the GNU L length extension. */
+ strfmon (s, m, "abc%-11ndef%==i%%", d, d);
+ strfmon (s, m, "%%abc%-11ndef%==Li%=%i", d, ld, d);
+ strfmon (s, m, "%Li", ld);
+ strfmon (s, m, "%11Li", ld);
+ strfmon (s, m, "%#5Li", ld);
+ strfmon (s, m, "%=*#5Li", ld);
+ strfmon (s, m, "%=0#5Li", ld);
+ strfmon (s, m, "%^#5Li", ld);
+ strfmon (s, m, "%^#5.0Li", ld);
+ strfmon (s, m, "%^#5.4Li", ld);
+ strfmon (s, m, "%(#5Li", ld);
+ strfmon (s, m, "%(!#5Li", ld);
+ /* Formats with the wrong types used. */
+ strfmon (s, m, "%Ln", d); /* { dg-warning "format" "wrong type" } */
+ strfmon (s, m, "%n", ld); /* { dg-warning "format" "wrong type" } */
+ /* The + and ( flags cannot be used together. */
+ strfmon (s, m, "%+(i", d); /* { dg-warning "flag" "+ and ( flags" } */
+ strfmon (s, m, "%(+i", d); /* { dg-warning "flag" "+ and ( flags" } */
+ /* Although empty precision is OK for printf, it isn't here. */
+ strfmon (s, m, "%#.5n", d); /* { dg-warning "empty" "empty left precision" } */
+ strfmon (s, m, "%#5.n", d); /* { dg-warning "empty" "empty right precision" } */
+ /* However, zero is a valid value for width and precisions. */
+ strfmon (s, m, "%0#0.0n", d);
+ /* Test bogus %% constructions. */
+ strfmon (s, m, "%^%"); /* { dg-warning "format" "bogus %%" } */
+ strfmon (s, m, "%!%\n"); /* { dg-warning "format" "bogus %%" } */
+ strfmon (s, m, "%5%\n"); /* { dg-warning "format" "bogus %%" } */
+ strfmon (s, m, "%.5%\n"); /* { dg-warning "format" "bogus %%" } */
+ strfmon (s, m, "%#5%\n"); /* { dg-warning "format" "bogus %%" } */
+ /* Miscellaneous bogus formats. */
+ strfmon (s, m, "%n%n", d); /* { dg-warning "arguments" "too few args" } */
+ strfmon (s, m, ""); /* { dg-warning "zero-length" "empty" } */
+ strfmon (s, m, NULL); /* { dg-warning "null" "null format string" } */
+ strfmon (s, m, "%"); /* { dg-warning "trailing" "tailing %" } */
+ strfmon (s, m, "%n\0", d); /* { dg-warning "embedded" "embedded NUL" } */
+ strfmon (s, m, "%^^n", d); /* { dg-warning "repeated" "repeated flag" } */
+}