diff options
author | Joseph Myers <jsm28@cam.ac.uk> | 2000-08-25 16:27:57 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2000-08-25 16:27:57 +0100 |
commit | 343b7260c6f4c4164fd65368a7d2391defcbd098 (patch) | |
tree | 518850ff2e272e9d5d1d8fe45cb19896c30927f5 /gcc | |
parent | 22efd68702b68b1f7577b1d96867ebb550dd1c5b (diff) | |
download | gcc-343b7260c6f4c4164fd65368a7d2391defcbd098.zip gcc-343b7260c6f4c4164fd65368a7d2391defcbd098.tar.gz gcc-343b7260c6f4c4164fd65368a7d2391defcbd098.tar.bz2 |
c-common.c (time_char_table): Don't allow width and flags with "z" format.
* c-common.c (time_char_table): Don't allow width and flags with
"z" format.
testsuite:
* gcc.dg/format-ext-3.c, gcc.dg/format-ext-4.c,
gcc.dg/format-ext-5.c: New tests.
From-SVN: r35984
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-common.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format-ext-3.c | 217 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format-ext-4.c | 20 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format-ext-5.c | 21 |
6 files changed, 270 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e07ca1c..ae8f0ca 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2000-08-25 Joseph S. Myers <jsm28@cam.ac.uk> + + * c-common.c (time_char_table): Don't allow width and flags with + "z" format. + 2000-08-25 Jakub Jelinek <jakub@redhat.com> * config/i386/i386.c (ix86_expand_branch): Treat GE and GEU the same diff --git a/gcc/c-common.c b/gcc/c-common.c index e2e57c5..cf145ca 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -1294,7 +1294,8 @@ static format_char_info time_char_table[] = { { "e", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Ow9" }, { "j", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Oow" }, { "Vu", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Ow9" }, - { "Gz", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Oow9" }, + { "G", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0Oow9" }, + { "z", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Oo9" }, { "kls", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "-_0OGw" }, { "ABZa", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "^#" }, { "p", 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "#" }, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 99afdaf..b1b5272 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2000-08-25 Joseph S. Myers <jsm28@cam.ac.uk> + + * gcc.dg/format-ext-3.c, gcc.dg/format-ext-4.c, + gcc.dg/format-ext-5.c: New tests. + 2000-08-25 Jakub Jelinek <jakub@redhat.com> * testsuite/g++.old-deja/g++.other/crash22.C: New test. diff --git a/gcc/testsuite/gcc.dg/format-ext-3.c b/gcc/testsuite/gcc.dg/format-ext-3.c new file mode 100644 index 0000000..54ae6f3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format-ext-3.c @@ -0,0 +1,217 @@ +/* Test for format extensions beyond the C standard and X/Open standard. + Test for strftime formats. +*/ +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +typedef __SIZE_TYPE__ size_t; + +struct tm; + +extern size_t strftime (char *, size_t, const char *, const struct tm *); + +void +foo (char *s, size_t m, const struct tm *tp) +{ + /* GCC accepts the "-", "_" and "0" flags to control padding on numeric + formats. It also accepts width on these formats. + */ + /* Basic tests of parts on their own. */ + strftime (s, m, "%5C%-C%_C%0C", tp); + /* Correct usages. */ + strftime (s, m, "%-5C%_5C%05C%-5d%_5d%05d%-5e%_5e%05e%-5G%_5G%05G", tp); + strftime (s, m, "%-5H%_5H%05H%-5I%_5I%05I%-5j%_5j%05j%-5m%_5m%05m", tp); + strftime (s, m, "%-5M%_5M%05M%-5S%_5S%05S%-5u%_5u%05u%-5U%_5U%05U", tp); + strftime (s, m, "%-5V%_5V%05V%-5w%_5w%05w%-5W%_5W%05W%-5Y%_5Y%05Y", tp); + /* Correct usages with GNU extension conversion characters. */ + strftime (s, m, "%-5k%_5k%05k%-5l%_5l%05l%-20s%_20s%020s", tp); + /* Correct usages with Y2K problems. */ + strftime (s, m, "%-5g%_5g%05g%-5y%_5y%05y", tp); /* { dg-warning "only last 2" "2-digit year" } */ + /* Incorrect usages. */ + strftime (s, m, "%5a", tp); /* { dg-warning "width" "bad %a" } */ + strftime (s, m, "%-a", tp); /* { dg-warning "flag" "bad %a" } */ + strftime (s, m, "%_a", tp); /* { dg-warning "flag" "bad %a" } */ + strftime (s, m, "%0a", tp); /* { dg-warning "flag" "bad %a" } */ + strftime (s, m, "%5A", tp); /* { dg-warning "width" "bad %A" } */ + strftime (s, m, "%-A", tp); /* { dg-warning "flag" "bad %A" } */ + strftime (s, m, "%_A", tp); /* { dg-warning "flag" "bad %A" } */ + strftime (s, m, "%0A", tp); /* { dg-warning "flag" "bad %A" } */ + strftime (s, m, "%5b", tp); /* { dg-warning "width" "bad %b" } */ + strftime (s, m, "%-b", tp); /* { dg-warning "flag" "bad %b" } */ + strftime (s, m, "%_b", tp); /* { dg-warning "flag" "bad %b" } */ + strftime (s, m, "%0b", tp); /* { dg-warning "flag" "bad %b" } */ + strftime (s, m, "%5B", tp); /* { dg-warning "width" "bad %B" } */ + strftime (s, m, "%-B", tp); /* { dg-warning "flag" "bad %B" } */ + strftime (s, m, "%_B", tp); /* { dg-warning "flag" "bad %B" } */ + strftime (s, m, "%0B", tp); /* { dg-warning "flag" "bad %B" } */ + strftime (s, m, "%5F", tp); /* { dg-warning "width" "bad %F" } */ + strftime (s, m, "%-F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%_F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%0F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%5h", tp); /* { dg-warning "width" "bad %h" } */ + strftime (s, m, "%-h", tp); /* { dg-warning "flag" "bad %h" } */ + strftime (s, m, "%_h", tp); /* { dg-warning "flag" "bad %h" } */ + strftime (s, m, "%0h", tp); /* { dg-warning "flag" "bad %h" } */ + strftime (s, m, "%5n", tp); /* { dg-warning "width" "bad %n" } */ + strftime (s, m, "%-n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%_n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%0n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%5p", tp); /* { dg-warning "width" "bad %p" } */ + strftime (s, m, "%-p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%_p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%0p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%5r", tp); /* { dg-warning "width" "bad %r" } */ + strftime (s, m, "%-r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%_r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%0r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%5R", tp); /* { dg-warning "width" "bad %R" } */ + strftime (s, m, "%-R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%_R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%0R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%5t", tp); /* { dg-warning "width" "bad %t" } */ + strftime (s, m, "%-t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%_t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%0t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%5T", tp); /* { dg-warning "width" "bad %T" } */ + strftime (s, m, "%-T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%_T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%0T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%5X", tp); /* { dg-warning "width" "bad %X" } */ + strftime (s, m, "%-X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%_X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%0X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%5z", tp); /* { dg-warning "width" "bad %z" } */ + strftime (s, m, "%-z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%_z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%0z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%5Z", tp); /* { dg-warning "width" "bad %Z" } */ + strftime (s, m, "%-Z", tp); /* { dg-warning "flag" "bad %Z" } */ + strftime (s, m, "%_Z", tp); /* { dg-warning "flag" "bad %Z" } */ + strftime (s, m, "%0Z", tp); /* { dg-warning "flag" "bad %Z" } */ + /* Incorrect usages with Y2K problems. */ + strftime (s, m, "%5c", tp); /* { dg-warning "width" "bad %c" } */ + strftime (s, m, "%-c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%_c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%0c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%5D", tp); /* { dg-warning "width" "bad %D" } */ + strftime (s, m, "%-D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%_D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%0D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%5x", tp); /* { dg-warning "width" "bad %x" } */ + strftime (s, m, "%-x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%_x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%0x", tp); /* { dg-warning "flag" "bad %x" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 93 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 94 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 95 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 96 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 97 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 98 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 99 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 100 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 101 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 102 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 103 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 104 } */ + /* Incorrect usages with GNU extension conversion characters. */ + strftime (s, m, "%5P", tp); /* { dg-warning "width" "bad %P" } */ + strftime (s, m, "%-P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%_P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%0P", tp); /* { dg-warning "flag" "bad %P" } */ + /* The "^" and "#" flags control the case of the output. + ^ (uppercase) makes sense on aAbBhZ; # (change case) makes sense + on the same (though glibc ignores it on bh for some reason; for now our + implementation in GCC follows glibc) and on p. + */ + strftime (s, m, "%^a%#a%^A%#A%^b%^B%#B%^h%^Z%#Z%#p", tp); + /* Bad usages. */ + strftime (s, m, "%#b", tp); /* { dg-warning "flag" "bad %b" } */ + strftime (s, m, "%^C", tp); /* { dg-warning "flag" "bad %C" } */ + strftime (s, m, "%#C", tp); /* { dg-warning "flag" "bad %C" } */ + strftime (s, m, "%^d", tp); /* { dg-warning "flag" "bad %d" } */ + strftime (s, m, "%#d", tp); /* { dg-warning "flag" "bad %d" } */ + strftime (s, m, "%^e", tp); /* { dg-warning "flag" "bad %e" } */ + strftime (s, m, "%#e", tp); /* { dg-warning "flag" "bad %e" } */ + strftime (s, m, "%^F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%#F", tp); /* { dg-warning "flag" "bad %F" } */ + strftime (s, m, "%^G", tp); /* { dg-warning "flag" "bad %G" } */ + strftime (s, m, "%#G", tp); /* { dg-warning "flag" "bad %G" } */ + strftime (s, m, "%#h", tp); /* { dg-warning "flag" "bad %h" } */ + strftime (s, m, "%^H", tp); /* { dg-warning "flag" "bad %H" } */ + strftime (s, m, "%#H", tp); /* { dg-warning "flag" "bad %H" } */ + strftime (s, m, "%^I", tp); /* { dg-warning "flag" "bad %I" } */ + strftime (s, m, "%#I", tp); /* { dg-warning "flag" "bad %I" } */ + strftime (s, m, "%^j", tp); /* { dg-warning "flag" "bad %j" } */ + strftime (s, m, "%#j", tp); /* { dg-warning "flag" "bad %j" } */ + strftime (s, m, "%^m", tp); /* { dg-warning "flag" "bad %m" } */ + strftime (s, m, "%#m", tp); /* { dg-warning "flag" "bad %m" } */ + strftime (s, m, "%^M", tp); /* { dg-warning "flag" "bad %M" } */ + strftime (s, m, "%#M", tp); /* { dg-warning "flag" "bad %M" } */ + strftime (s, m, "%^n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%#n", tp); /* { dg-warning "flag" "bad %n" } */ + strftime (s, m, "%^p", tp); /* { dg-warning "flag" "bad %p" } */ + strftime (s, m, "%^r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%#r", tp); /* { dg-warning "flag" "bad %r" } */ + strftime (s, m, "%^R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%#R", tp); /* { dg-warning "flag" "bad %R" } */ + strftime (s, m, "%^S", tp); /* { dg-warning "flag" "bad %S" } */ + strftime (s, m, "%#S", tp); /* { dg-warning "flag" "bad %S" } */ + strftime (s, m, "%^t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%#t", tp); /* { dg-warning "flag" "bad %t" } */ + strftime (s, m, "%^T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%#T", tp); /* { dg-warning "flag" "bad %T" } */ + strftime (s, m, "%^u", tp); /* { dg-warning "flag" "bad %u" } */ + strftime (s, m, "%#u", tp); /* { dg-warning "flag" "bad %u" } */ + strftime (s, m, "%^U", tp); /* { dg-warning "flag" "bad %U" } */ + strftime (s, m, "%#U", tp); /* { dg-warning "flag" "bad %U" } */ + strftime (s, m, "%^V", tp); /* { dg-warning "flag" "bad %V" } */ + strftime (s, m, "%#V", tp); /* { dg-warning "flag" "bad %V" } */ + strftime (s, m, "%^w", tp); /* { dg-warning "flag" "bad %w" } */ + strftime (s, m, "%#w", tp); /* { dg-warning "flag" "bad %w" } */ + strftime (s, m, "%^W", tp); /* { dg-warning "flag" "bad %W" } */ + strftime (s, m, "%#W", tp); /* { dg-warning "flag" "bad %W" } */ + strftime (s, m, "%^X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%#X", tp); /* { dg-warning "flag" "bad %X" } */ + strftime (s, m, "%^Y", tp); /* { dg-warning "flag" "bad %Y" } */ + strftime (s, m, "%#Y", tp); /* { dg-warning "flag" "bad %Y" } */ + strftime (s, m, "%^z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%#z", tp); /* { dg-warning "flag" "bad %z" } */ + strftime (s, m, "%^P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%#P", tp); /* { dg-warning "flag" "bad %P" } */ + strftime (s, m, "%^k", tp); /* { dg-warning "flag" "bad %k" } */ + strftime (s, m, "%#k", tp); /* { dg-warning "flag" "bad %k" } */ + strftime (s, m, "%^l", tp); /* { dg-warning "flag" "bad %l" } */ + strftime (s, m, "%#l", tp); /* { dg-warning "flag" "bad %l" } */ + strftime (s, m, "%^s", tp); /* { dg-warning "flag" "bad %s" } */ + strftime (s, m, "%#s", tp); /* { dg-warning "flag" "bad %s" } */ + /* Bad usages with Y2K problems. */ + strftime (s, m, "%^c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%#c", tp); /* { dg-warning "flag" "bad %c" } */ + strftime (s, m, "%^D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%#D", tp); /* { dg-warning "flag" "bad %D" } */ + strftime (s, m, "%^g", tp); /* { dg-warning "flag" "bad %g" } */ + strftime (s, m, "%#g", tp); /* { dg-warning "flag" "bad %g" } */ + strftime (s, m, "%^x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%#x", tp); /* { dg-warning "flag" "bad %x" } */ + strftime (s, m, "%^y", tp); /* { dg-warning "flag" "bad %y" } */ + strftime (s, m, "%#y", tp); /* { dg-warning "flag" "bad %y" } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 189 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 190 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 191 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 192 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 193 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 194 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 195 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 196 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 197 } */ + /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 198 } */ + /* GCC also accepts the glibc format extensions %P, %k, %l, %s. */ + strftime (s, m, "%P%k%l%s", tp); + /* GCC also accepts the glibc extension of the "O" modifier on some + more formats. The cases where it is rejected altogether are + covered in c99-strftime-1.c, except for the extension %P. + */ + strftime (s, m, "%OC%Og%OG%Oj%OY%Oz%Ok%Ol%Os", tp); /* { dg-warning "only last 2" "2-digit year" } */ + strftime (s, m, "%OP", tp); /* { dg-warning "flag" "bad %OP" } */ +} diff --git a/gcc/testsuite/gcc.dg/format-ext-4.c b/gcc/testsuite/gcc.dg/format-ext-4.c new file mode 100644 index 0000000..c0cf740 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format-ext-4.c @@ -0,0 +1,20 @@ +/* Test for scanf formats. %a extensions. */ +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu89 -Wformat" } */ + +typedef __WCHAR_TYPE__ wchar_t; + +extern int scanf (const char *, ...); + +void +foo (char **sp, wchar_t **lsp) +{ + /* %a formats for allocation, only recognised in C90 mode, are a + GNU extension. Followed by other characters, %a is not treated + specially. + */ + scanf ("%as", sp); + scanf ("%aS", lsp); + scanf ("%a[bcd]", sp); +} diff --git a/gcc/testsuite/gcc.dg/format-ext-5.c b/gcc/testsuite/gcc.dg/format-ext-5.c new file mode 100644 index 0000000..e3cce44 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format-ext-5.c @@ -0,0 +1,21 @@ +/* Test for gettext default attributes. */ +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +extern int printf (const char *, ...); + +extern char *gettext (const char *); +extern char *dgettext (const char *, const char *); +extern char *dcgettext (const char *, const char *, int); + +void +foo (int i, long l) +{ + printf (gettext ("%d"), i); + printf (gettext ("%ld"), i); /* { dg-warning "format" "gettext" } */ + printf (dgettext ("", "%d"), i); + printf (dgettext ("", "%ld"), i); /* { dg-warning "format" "dgettext" } */ + printf (dcgettext ("", "%d", 0), i); + printf (dcgettext ("", "%ld", 0), i); /* { dg-warning "format" "dcgettext" } */ +} |