summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/format
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2007-09-17 22:07:46 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2007-09-17 22:07:46 +0000
commit99dc6a64df2d07352931aef12364d3b4a200f929 (patch)
tree29b960a466f572a1131b689d972ec8b615681fd0 /gcc/testsuite/gcc.dg/format
parent6d54e88630b18e7610bad2881af7c8230a1cc916 (diff)
downloadgcc-99dc6a64df2d07352931aef12364d3b4a200f929.tar.gz
* c-format.h (format_kind_info): Add alloc_char field.
* c-format.c (scanf_flag_specs): Add 'm'. (scanf_flag_pairs): Add 'a', 'm' pair. (scan_char_table): Allow 'm' modifier for c, s, [, C and S. (format_types_orig): Add alloc_char fields. (check_format_info_main): Rename aflag to alloc_flag. Handle fki->alloc_char. modifier after width and before length modifiers. Move FMT_FLAG_SCANF_A_KLUDGE handling before length modifiers as well. * config/sol2-c.c (solaris_format_types): Add alloc_char field. * gcc.dg/format/c90-scanf-5.c: New test. * gcc.dg/format/c99-scanf-4.c: New test. * gcc.dg/format/ext-7.c: New test. * gcc.dg/format/ext-8.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@128555 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/format')
-rw-r--r--gcc/testsuite/gcc.dg/format/c90-scanf-5.c19
-rw-r--r--gcc/testsuite/gcc.dg/format/c99-scanf-4.c19
-rw-r--r--gcc/testsuite/gcc.dg/format/ext-7.c85
-rw-r--r--gcc/testsuite/gcc.dg/format/ext-8.c56
4 files changed, 179 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/format/c90-scanf-5.c b/gcc/testsuite/gcc.dg/format/c90-scanf-5.c
new file mode 100644
index 00000000000..c94e25f222a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/c90-scanf-5.c
@@ -0,0 +1,19 @@
+/* Test for scanf formats. Formats using extensions to the standard
+ should be rejected in strict pedantic mode.
+*/
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
+
+#include "format.h"
+
+void
+foo (char **sp, wchar_t **lsp)
+{
+ /* m assignment-allocation modifier, recognized in both C90
+ and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension. */
+ scanf ("%ms", sp); /* { dg-warning "C" "%ms" } */
+ scanf ("%mS", lsp); /* { dg-warning "C" "%mS" } */
+ scanf ("%mls", lsp); /* { dg-warning "C" "%mls" } */
+ scanf ("%m[bcd]", sp); /* { dg-warning "C" "%m[]" } */
+ scanf ("%ml[bcd]", lsp); /* { dg-warning "C" "%ml[]" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/c99-scanf-4.c b/gcc/testsuite/gcc.dg/format/c99-scanf-4.c
new file mode 100644
index 00000000000..9c7a5e4b273
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/c99-scanf-4.c
@@ -0,0 +1,19 @@
+/* Test for scanf formats. Formats using extensions to the standard
+ should be rejected in strict pedantic mode.
+*/
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
+
+#include "format.h"
+
+void
+foo (char **sp, wchar_t **lsp)
+{
+ /* m assignment-allocation modifier, recognized in both C90
+ and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension. */
+ scanf ("%ms", sp); /* { dg-warning "C" "%ms" } */
+ scanf ("%mS", lsp); /* { dg-warning "C" "%mS" } */
+ scanf ("%mls", lsp); /* { dg-warning "C" "%mls" } */
+ scanf ("%m[bcd]", sp); /* { dg-warning "C" "%m[]" } */
+ scanf ("%ml[bcd]", lsp); /* { dg-warning "C" "%ml[]" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ext-7.c b/gcc/testsuite/gcc.dg/format/ext-7.c
new file mode 100644
index 00000000000..d9bd0e8ffd0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ext-7.c
@@ -0,0 +1,85 @@
+/* Test for scanf formats. %a and %m extensions. */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu89 -Wformat" } */
+
+#include "format.h"
+
+void
+foo (char **sp, wchar_t **lsp, int *ip, float *fp, void **pp, double *dp)
+{
+ /* %a formats for allocation, only recognized in C90 mode, are a
+ GNU extension. Followed by other characters, %a is not treated
+ specially.
+ */
+ scanf ("%as", sp);
+ scanf ("%aS", lsp);
+ scanf ("%las", dp);
+ scanf ("%la", lsp); /* { dg-warning "but argument 2 has type" } */
+ scanf ("%las", lsp); /* { dg-warning "but argument 2 has type" } */
+ scanf ("%a[bcd]", sp);
+ scanf ("%la[bcd]", dp);
+ scanf ("%*as");
+ scanf ("%*aS");
+ scanf ("%*las"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*a[bcd]");
+ scanf ("%*la[bcd]"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%10as", sp);
+ scanf ("%5aS", lsp);
+ scanf ("%9las", dp);
+ scanf ("%25a[bcd]", sp);
+ scanf ("%48la[bcd]", dp);
+ scanf ("%*10as");
+ scanf ("%*5aS");
+ scanf ("%*9las"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*25a[bcd]");
+ scanf ("%*48la[bcd]"); /* { dg-warning "assignment suppression and length modifier" } */
+
+ /* m assignment-allocation modifier, recognized in both C90
+ and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension. */
+ scanf ("%ms", sp);
+ scanf ("%mS", lsp);
+ scanf ("%mls", lsp);
+ scanf ("%m[bcd]", sp);
+ scanf ("%ml[bcd]", lsp);
+ scanf ("%mc", sp);
+ scanf ("%mlc", lsp);
+ scanf ("%mC", lsp);
+ scanf ("%*ms");
+ scanf ("%*mS");
+ scanf ("%*mls"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*m[bcd]");
+ scanf ("%*ml[bcd]"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*mc");
+ scanf ("%*mlc"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*mC");
+ scanf ("%10ms", sp);
+ scanf ("%5mS", lsp);
+ scanf ("%9mls", lsp);
+ scanf ("%25m[bcd]", sp);
+ scanf ("%41ml[bcd]", lsp);
+ scanf ("%131mc", sp);
+ scanf ("%27mlc", lsp);
+ scanf ("%2mC", lsp);
+ scanf ("%*10ms");
+ scanf ("%*5mS");
+ scanf ("%*9mls"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*25m[bcd]");
+ scanf ("%*41ml[bcd]"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*131mc");
+ scanf ("%*27mlc"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*2mC");
+
+ scanf ("%md", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mi", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mo", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mu", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mx", ip); /* { dg-warning "flag used with" } */
+ scanf ("%me", fp); /* { dg-warning "flag used with" } */
+ scanf ("%mf", fp); /* { dg-warning "flag used with" } */
+ scanf ("%mg", fp); /* { dg-warning "flag used with" } */
+ scanf ("%mp", pp); /* { dg-warning "flag used with" } */
+
+ scanf ("%mas", sp); /* { dg-warning "flag together" } */
+ scanf ("%maS", lsp); /* { dg-warning "flag together" } */
+ scanf ("%ma[bcd]", sp); /* { dg-warning "flag together" } */
+}
diff --git a/gcc/testsuite/gcc.dg/format/ext-8.c b/gcc/testsuite/gcc.dg/format/ext-8.c
new file mode 100644
index 00000000000..b50cc81d573
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/ext-8.c
@@ -0,0 +1,56 @@
+/* Test for scanf formats. %m extensions. */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu99 -Wformat" } */
+
+#include "format.h"
+
+void
+foo (char **sp, wchar_t **lsp, int *ip, float *fp, void **pp)
+{
+ /* m assignment-allocation modifier, recognized in both C90
+ and C99 modes, is a POSIX and ISO/IEC WDTR 24731-2 extension. */
+ scanf ("%ms", sp);
+ scanf ("%mS", lsp);
+ scanf ("%mls", lsp);
+ scanf ("%m[bcd]", sp);
+ scanf ("%ml[bcd]", lsp);
+ scanf ("%mc", sp);
+ scanf ("%mlc", lsp);
+ scanf ("%mC", lsp);
+ scanf ("%*ms");
+ scanf ("%*mS");
+ scanf ("%*mls"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*m[bcd]");
+ scanf ("%*ml[bcd]"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*mc");
+ scanf ("%*mlc"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*mC");
+ scanf ("%10ms", sp);
+ scanf ("%5mS", lsp);
+ scanf ("%9mls", lsp);
+ scanf ("%25m[bcd]", sp);
+ scanf ("%41ml[bcd]", lsp);
+ scanf ("%131mc", sp);
+ scanf ("%27mlc", lsp);
+ scanf ("%2mC", lsp);
+ scanf ("%*10ms");
+ scanf ("%*5mS");
+ scanf ("%*9mls"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*25m[bcd]");
+ scanf ("%*41ml[bcd]"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*131mc");
+ scanf ("%*27mlc"); /* { dg-warning "assignment suppression and length modifier" } */
+ scanf ("%*2mC");
+
+ scanf ("%md", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mi", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mo", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mu", ip); /* { dg-warning "flag used with" } */
+ scanf ("%mx", ip); /* { dg-warning "flag used with" } */
+ scanf ("%ma", fp); /* { dg-warning "flag used with" } */
+ scanf ("%mA", fp); /* { dg-warning "flag used with" } */
+ scanf ("%me", fp); /* { dg-warning "flag used with" } */
+ scanf ("%mf", fp); /* { dg-warning "flag used with" } */
+ scanf ("%mg", fp); /* { dg-warning "flag used with" } */
+ scanf ("%mp", pp); /* { dg-warning "flag used with" } */
+}