summaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2001-11-25 18:54:12 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2001-11-25 18:54:12 +0000
commitb2306c7fcbb2227fc02f326298e49f2740f562f2 (patch)
tree64f1447d44d75dece4a7f5012528ee7b1f4ed583 /gcc/testsuite
parentfca7aa70087a2a8769015fea573c4189191f7872 (diff)
downloadgcc-b2306c7fcbb2227fc02f326298e49f2740f562f2.tar.gz
* c-format.c (FMT_FLAG_DOLLAR_GAP_POINTER_OK): New.
(format_types): Use it for scanf. (dollar_arguments_pointer_p): New. (init_dollar_format_checking): Store details of which arguments are pointers. (maybe_read_dollar_number): Reallocate dollar_arguments_pointer_p. (finish_dollar_format_checking): Take extra parameter pointer_gap_ok. Treat unused arguments differently if pointer_gap_ok and the unused arguments are pointers. (check_format_info_main): Pass extra argument to finish_dollar_format_checking. * doc/invoke.texi (-Wno-format-extra-args): Document behavior when unused arguments are present between used arguments with operand numbers. testsuite: * gcc.dg/format/strfmon-1.c: Update comments. Adjust examples from Austin Group draft 7. * gcc.dg/format/xopen-1.c: Update comments. Add tests for gaps in scanf format arguments. * gcc.dg/format/no-exargs-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@47327 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/gcc.dg/format/no-exargs-2.c27
-rw-r--r--gcc/testsuite/gcc.dg/format/strfmon-1.c10
-rw-r--r--gcc/testsuite/gcc.dg/format/xopen-1.c21
4 files changed, 57 insertions, 9 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c1a7fdeb1db..3a69d3cbb53 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2001-11-25 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * gcc.dg/format/strfmon-1.c: Update comments. Adjust examples
+ from Austin Group draft 7.
+ * gcc.dg/format/xopen-1.c: Update comments. Add tests for gaps in
+ scanf format arguments.
+ * gcc.dg/format/no-exargs-2.c: New test.
+
2001-11-25 Nathan Sidwell <nathan@codesourcery.com>
* g++.dg/abi/vbase8-4.C: New test.
diff --git a/gcc/testsuite/gcc.dg/format/no-exargs-2.c b/gcc/testsuite/gcc.dg/format/no-exargs-2.c
new file mode 100644
index 00000000000..3fa9285784e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/no-exargs-2.c
@@ -0,0 +1,27 @@
+/* Test for warnings for extra format arguments being disabled by
+ -Wno-format-extra-args. Test which warnings still apply with $
+ operand numbers. */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat -Wno-format-extra-args" } */
+
+#include "format.h"
+
+void
+foo (int i, int *ip, va_list va)
+{
+ printf ("%3$d%1$d", i, i, i); /* { dg-warning "before used" "unused $ operand" } */
+ printf ("%2$d%1$d", i, i, i);
+ vprintf ("%3$d%1$d", va); /* { dg-warning "before used" "unused $ operand" } */
+ /* With scanf formats, gaps in the used arguments are allowed only if the
+ arguments are all pointers. In such a case, should only give the lesser
+ warning about unused arguments rather than the more serious one about
+ argument gaps. */
+ scanf ("%3$d%1$d", ip, ip, ip);
+ /* If there are non-pointer arguments unused at the end, this is also OK. */
+ scanf ("%3$d%1$d", ip, ip, ip, i);
+ scanf ("%3$d%1$d", ip, i, ip); /* { dg-warning "before used" "unused $ scanf non-pointer operand" } */
+ /* Can't check the arguments in the vscanf case, so should suppose the
+ lesser problem. */
+ vscanf ("%3$d%1$d", va);
+}
diff --git a/gcc/testsuite/gcc.dg/format/strfmon-1.c b/gcc/testsuite/gcc.dg/format/strfmon-1.c
index cf381b87d2d..d163751328c 100644
--- a/gcc/testsuite/gcc.dg/format/strfmon-1.c
+++ b/gcc/testsuite/gcc.dg/format/strfmon-1.c
@@ -8,7 +8,7 @@
void
foo (char *s, size_t m, double d, long double ld)
{
- /* Examples of valid formats from Austin Group draft 5. */
+ /* Examples of valid formats from Austin Group draft 7. */
strfmon (s, m, "%n", d);
strfmon (s, m, "%11n", d);
strfmon (s, m, "%#5n", d);
@@ -18,7 +18,9 @@ foo (char *s, size_t m, double d, long double ld)
strfmon (s, m, "%^#5.0n", d);
strfmon (s, m, "%^#5.4n", d);
strfmon (s, m, "%(#5n", d);
- strfmon (s, m, "%(!#5n", d);
+ strfmon (s, m, "%!(#5n", d);
+ strfmon (s, m, "%-14#5.4n", d);
+ strfmon (s, m, "%14#5.4n", 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);
@@ -31,7 +33,9 @@ foo (char *s, size_t m, double d, long double ld)
strfmon (s, m, "%^#5.0Li", ld);
strfmon (s, m, "%^#5.4Li", ld);
strfmon (s, m, "%(#5Li", ld);
- strfmon (s, m, "%(!#5Li", ld);
+ strfmon (s, m, "%!(#5Li", ld);
+ strfmon (s, m, "%-14#5.4Li", ld);
+ strfmon (s, m, "%14#5.4Li", 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" } */
diff --git a/gcc/testsuite/gcc.dg/format/xopen-1.c b/gcc/testsuite/gcc.dg/format/xopen-1.c
index 38cba1eb735..934dcb18cd8 100644
--- a/gcc/testsuite/gcc.dg/format/xopen-1.c
+++ b/gcc/testsuite/gcc.dg/format/xopen-1.c
@@ -1,6 +1,5 @@
/* Test for X/Open format extensions, as found in the
- Single Unix Specification and in Austin Group draft 4, subject to some
- Aardvark problem reports approved as changes.
+ Single Unix Specification and in Austin Group draft 7.
*/
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
/* { dg-do compile } */
@@ -88,10 +87,6 @@ foo (int i, unsigned int u, wint_t lc, wchar_t *ls, int *ip, double d,
printf ("%'p", p); /* { dg-warning "flag" "bad use of ' flag" } */
printf ("%'n", n); /* { dg-warning "flag" "bad use of ' flag" } */
/* The use of operand number $ formats is an X/Open extension. */
- /* Banning gaps in the arguments used with scanf was covered in Aardvark
- report XSHd4 ERN 164, which was rejected, but implementation without
- such a ban still isn't possible within ISO C.
- */
scanf ("%1$d", ip);
printf ("%1$d", i);
printf ("%1$d", l); /* { dg-warning "arg 2" "mismatched args with $ format" } */
@@ -110,6 +105,20 @@ foo (int i, unsigned int u, wint_t lc, wchar_t *ls, int *ip, double d,
printf ("%3$d%1$d", i, i, i); /* { dg-warning "before used" "unused $ operand" } */
printf ("%2$d%1$d", i, i, i); /* { dg-warning "unused" "unused $ operand" } */
vprintf ("%3$d%1$d", va); /* { dg-warning "before used" "unused $ operand" } */
+ /* With scanf formats, gaps in the used arguments are allowed only if the
+ arguments are all pointers. In such a case, should only give the lesser
+ warning about unused arguments rather than the more serious one about
+ argument gaps. */
+ scanf ("%3$d%1$d", ip, ip, ip); /* { dg-bogus "before used" "unused $ scanf pointer operand" } */
+ /* { dg-warning "unused" "unused $ scanf pointer operand" { target *-*-* } 112 } */
+ /* If there are non-pointer arguments unused at the end, this is also OK. */
+ scanf ("%3$d%1$d", ip, ip, ip, i); /* { dg-bogus "before used" "unused $ scanf pointer operand" } */
+ /* { dg-warning "unused" "unused $ scanf pointer operand" { target *-*-* } 115 } */
+ scanf ("%3$d%1$d", ip, i, ip); /* { dg-warning "before used" "unused $ scanf non-pointer operand" } */
+ /* Can't check the arguments in the vscanf case, so should suppose the
+ lesser problem. */
+ vscanf ("%3$d%1$d", va); /* { dg-bogus "before used" "unused $ scanf pointer operand" } */
+ /* { dg-warning "unused" "unused $ scanf pointer operand" { target *-*-* } 120 } */
scanf ("%2$*d%1$d", ip, ip); /* { dg-warning "operand" "operand number with suppression" } */
printf ("%1$d%1$d", i);
scanf ("%1$d%1$d", ip); /* { dg-warning "more than once" "multiple use of scanf argument" } */