OSDN Git Service

* c-common.c (check_format_info): Give the 'some locales' warning
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 22 Aug 2000 14:06:57 +0000 (14:06 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 22 Aug 2000 14:06:57 +0000 (14:06 +0000)
for strftime %Ey rather than the unconditional 'only last 2 digits
of year' one.

testsuite:
* gcc.dg/c90-strftime-2.c, gcc.dg/c99-strftime-1.c,
gcc.dg/c99-strftime-2.c: New tests.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@35874 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c90-strftime-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c99-strftime-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c99-strftime-2.c [new file with mode: 0644]

index 7372015..7d7e5f6 100644 (file)
@@ -1,3 +1,9 @@
+2000-08-22  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * c-common.c (check_format_info): Give the 'some locales' warning
+       for strftime %Ey rather than the unconditional 'only last 2 digits
+       of year' one.
+
 2000-08-22  Richard Henderson  <rth@cygnus.com>
 
        * alias.c (init_alias_analysis): Do not register
index 5e46af0..c72fbe7 100644 (file)
@@ -2162,11 +2162,12 @@ check_format_info (info, params)
        }
       if (wide && index (fci->flag_chars, 'w') == 0)
        warning ("width used with `%c' format", format_char);
-      if (index (fci->flag_chars, '2') != 0)
-       warning ("`%%%c' yields only last 2 digits of year", format_char);
-      else if (index (fci->flag_chars, '3') != 0)
+      if (index (fci->flag_chars, '3') != 0
+         || (format_char == 'y' && index (flag_chars, 'E')))
        warning ("`%%%c' yields only last 2 digits of year in some locales",
                 format_char);
+      else if (index (fci->flag_chars, '2') != 0)
+       warning ("`%%%c' yields only last 2 digits of year", format_char);
       if (precise && index (fci->flag_chars, 'p') == 0)
        warning ("precision used with `%c' format", format_char);
       if (aflag && index (fci->flag_chars, 'a') == 0)
index 5fe1538..45221fb 100644 (file)
@@ -1,3 +1,8 @@
+2000-08-22  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.dg/c90-strftime-2.c, gcc.dg/c99-strftime-1.c,
+       gcc.dg/c99-strftime-2.c: New tests.
+
 2000-08-22  Richard Henderson  <rth@cygnus.com>
 
        * gcc.c-torture/execute/20000822-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/c90-strftime-2.c b/gcc/testsuite/gcc.dg/c90-strftime-2.c
new file mode 100644 (file)
index 0000000..4d6c289
--- /dev/null
@@ -0,0 +1,35 @@
+/* Test for strftime formats.  Rejection of formats using C99 features in
+   pedantic C90 mode.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1990 -pedantic -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)
+{
+  strftime (s, m, "%C", tp); /* { dg-warning "C" "%C not in C90" } */
+  strftime (s, m, "%D", tp); /* { dg-warning "C" "%D not in C90" } */
+  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 17 } */
+  strftime (s, m, "%e", tp); /* { dg-warning "C" "%e not in C90" } */
+  strftime (s, m, "%F", tp); /* { dg-warning "C" "%F not in C90" } */
+  strftime (s, m, "%g", tp); /* { dg-warning "C" "%g not in C90" } */
+  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 21 } */
+  strftime (s, m, "%G", tp); /* { dg-warning "C" "%G not in C90" } */
+  strftime (s, m, "%h", tp); /* { dg-warning "C" "%h not in C90" } */
+  strftime (s, m, "%n", tp); /* { dg-warning "C" "%n not in C90" } */
+  strftime (s, m, "%r", tp); /* { dg-warning "C" "%r not in C90" } */
+  strftime (s, m, "%R", tp); /* { dg-warning "C" "%R not in C90" } */
+  strftime (s, m, "%t", tp); /* { dg-warning "C" "%t not in C90" } */
+  strftime (s, m, "%T", tp); /* { dg-warning "C" "%T not in C90" } */
+  strftime (s, m, "%u", tp); /* { dg-warning "C" "%u not in C90" } */
+  strftime (s, m, "%V", tp); /* { dg-warning "C" "%V not in C90" } */
+  strftime (s, m, "%z", tp); /* { dg-warning "C" "%z not in C90" } */
+  strftime (s, m, "%EX", tp); /* { dg-warning "C" "%E not in C90" } */
+  strftime (s, m, "%OW", tp); /* { dg-warning "C" "%O not in C90" } */
+}
diff --git a/gcc/testsuite/gcc.dg/c99-strftime-1.c b/gcc/testsuite/gcc.dg/c99-strftime-1.c
new file mode 100644 (file)
index 0000000..4ab0a41
--- /dev/null
@@ -0,0 +1,99 @@
+/* Test for strftime formats.  Formats using C99 features.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic -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)
+{
+  /* See ISO/IEC 9899:1990 (E) subclause 7.12.3.5 (pages 174-175).  */
+  /* Formats which are Y2K-compliant (no 2-digit years).  */
+  strftime (s, m, "%a%A%b%B%C%d%e%F%G%h%H%I%j%m%M%p%R%S%t%T%u%U%V%w%W%X%Y%z%Z%%", tp);
+  strftime (s, m, "%EC%EX%EY%Od%Oe%OH%OI%Om%OM%OS%Ou%OU%OV%Ow%OW", tp);
+  /* Formats with 2-digit years.  */
+  strftime (s, m, "%D", tp); /* { dg-warning "only last 2" "2-digit year" } */
+  strftime (s, m, "%g", tp); /* { dg-warning "only last 2" "2-digit year" } */
+  strftime (s, m, "%y", tp); /* { dg-warning "only last 2" "2-digit year" } */
+  strftime (s, m, "%Oy", tp); /* { dg-warning "only last 2" "2-digit year" } */
+  /* Formats with 2-digit years in some locales.  */
+  strftime (s, m, "%c", tp); /* { dg-warning "some locales" "2-digit year" } */
+  strftime (s, m, "%Ec", tp); /* { dg-warning "some locales" "2-digit year" } */
+  strftime (s, m, "%x", tp); /* { dg-warning "some locales" "2-digit year" } */
+  strftime (s, m, "%Ex", tp); /* { dg-warning "some locales" "2-digit year" } */
+  /* %Ey is explicitly an era offset not a 2-digit year; but in some
+     locales the E modifier may be ignored.
+  */
+  strftime (s, m, "%Ey", tp); /* { dg-warning "some locales" "2-digit year" } */
+  /* Bad uses of %E and %O.  */
+  strftime (s, m, "%EEY", tp); /* { dg-warning "multiple" "multiple %E/%O" } */
+  strftime (s, m, "%EOY", tp); /* { dg-warning "multiple" "multiple %E/%O" } */
+  strftime (s, m, "%OEV", tp); /* { dg-warning "multiple" "multiple %E/%O" } */
+  strftime (s, m, "%OOV", tp); /* { dg-warning "multiple" "multiple %E/%O" } */
+  strftime (s, m, "%Ea", tp); /* { dg-warning "flag" "bad %Ea" } */
+  strftime (s, m, "%EA", tp); /* { dg-warning "flag" "bad %EA" } */
+  strftime (s, m, "%Eb", tp); /* { dg-warning "flag" "bad %Eb" } */
+  strftime (s, m, "%EB", tp); /* { dg-warning "flag" "bad %EB" } */
+  strftime (s, m, "%Ed", tp); /* { dg-warning "flag" "bad %Ed" } */
+  strftime (s, m, "%ED", tp); /* { dg-warning "flag" "bad %ED" } */
+  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 43 } */
+  strftime (s, m, "%Ee", tp); /* { dg-warning "flag" "bad %Ee" } */
+  strftime (s, m, "%EF", tp); /* { dg-warning "flag" "bad %EF" } */
+  strftime (s, m, "%Eg", tp); /* { dg-warning "flag" "bad %Eg" } */
+  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 47 } */
+  strftime (s, m, "%EG", tp); /* { dg-warning "flag" "bad %EG" } */
+  strftime (s, m, "%Eh", tp); /* { dg-warning "flag" "bad %Eh" } */
+  strftime (s, m, "%EH", tp); /* { dg-warning "flag" "bad %EH" } */
+  strftime (s, m, "%EI", tp); /* { dg-warning "flag" "bad %EI" } */
+  strftime (s, m, "%Ej", tp); /* { dg-warning "flag" "bad %Ej" } */
+  strftime (s, m, "%Em", tp); /* { dg-warning "flag" "bad %Em" } */
+  strftime (s, m, "%EM", tp); /* { dg-warning "flag" "bad %EM" } */
+  strftime (s, m, "%En", tp); /* { dg-warning "flag" "bad %En" } */
+  strftime (s, m, "%Ep", tp); /* { dg-warning "flag" "bad %Ep" } */
+  strftime (s, m, "%Er", tp); /* { dg-warning "flag" "bad %Er" } */
+  strftime (s, m, "%ER", tp); /* { dg-warning "flag" "bad %ER" } */
+  strftime (s, m, "%ES", tp); /* { dg-warning "flag" "bad %ES" } */
+  strftime (s, m, "%Et", tp); /* { dg-warning "flag" "bad %Et" } */
+  strftime (s, m, "%ET", tp); /* { dg-warning "flag" "bad %ET" } */
+  strftime (s, m, "%Eu", tp); /* { dg-warning "flag" "bad %Eu" } */
+  strftime (s, m, "%EU", tp); /* { dg-warning "flag" "bad %EU" } */
+  strftime (s, m, "%EV", tp); /* { dg-warning "flag" "bad %EV" } */
+  strftime (s, m, "%Ew", tp); /* { dg-warning "flag" "bad %Ew" } */
+  strftime (s, m, "%EW", tp); /* { dg-warning "flag" "bad %EW" } */
+  strftime (s, m, "%Ez", tp); /* { dg-warning "flag" "bad %Ez" } */
+  strftime (s, m, "%EZ", tp); /* { dg-warning "flag" "bad %EZ" } */
+  strftime (s, m, "%E%", tp); /* { dg-warning "flag" "bad %E%" } */
+  strftime (s, m, "%Oa", tp); /* { dg-warning "flag" "bad %Oa" } */
+  strftime (s, m, "%OA", tp); /* { dg-warning "flag" "bad %OA" } */
+  strftime (s, m, "%Ob", tp); /* { dg-warning "flag" "bad %Ob" } */
+  strftime (s, m, "%OB", tp); /* { dg-warning "flag" "bad %OB" } */
+  strftime (s, m, "%Oc", tp); /* { dg-warning "flag" "bad %Oc" } */
+  /* { dg-warning "in some locales" "2-digit year" { target *-*-* } 75 } */
+  strftime (s, m, "%OC", tp); /* { dg-warning "flag|C" "bad %OC" } */
+  strftime (s, m, "%OD", tp); /* { dg-warning "flag" "bad %OD" } */
+  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 78 } */
+  strftime (s, m, "%OF", tp); /* { dg-warning "flag" "bad %OF" } */
+  strftime (s, m, "%Og", tp); /* { dg-warning "flag|C" "bad %Og" } */
+  /* { dg-warning "only last 2" "2-digit year" { target *-*-* } 81 } */
+  strftime (s, m, "%OG", tp); /* { dg-warning "flag|C" "bad %OG" } */
+  strftime (s, m, "%Oh", tp); /* { dg-warning "flag" "bad %Oh" } */
+  strftime (s, m, "%Oj", tp); /* { dg-warning "flag|C" "bad %Oj" } */
+  strftime (s, m, "%On", tp); /* { dg-warning "flag" "bad %On" } */
+  strftime (s, m, "%Op", tp); /* { dg-warning "flag" "bad %Op" } */
+  strftime (s, m, "%Or", tp); /* { dg-warning "flag" "bad %Or" } */
+  strftime (s, m, "%OR", tp); /* { dg-warning "flag" "bad %OR" } */
+  strftime (s, m, "%Ot", tp); /* { dg-warning "flag" "bad %Ot" } */
+  strftime (s, m, "%OT", tp); /* { dg-warning "flag" "bad %OT" } */
+  strftime (s, m, "%Ox", tp); /* { dg-warning "flag" "bad %Ox" } */
+  /* { dg-warning "in some locales" "2-digit year" { target *-*-* } 92 } */
+  strftime (s, m, "%OX", tp); /* { dg-warning "flag" "bad %OX" } */
+  strftime (s, m, "%OY", tp); /* { dg-warning "flag|C" "bad %OY" } */
+  strftime (s, m, "%Oz", tp); /* { dg-warning "flag|C" "bad %Oz" } */
+  strftime (s, m, "%OZ", tp); /* { dg-warning "flag" "bad %OZ" } */
+  strftime (s, m, "%O%", tp); /* { dg-warning "flag" "bad %O%" } */
+}
diff --git a/gcc/testsuite/gcc.dg/c99-strftime-2.c b/gcc/testsuite/gcc.dg/c99-strftime-2.c
new file mode 100644 (file)
index 0000000..45d8ef4
--- /dev/null
@@ -0,0 +1,27 @@
+/* Test for strftime formats.  Rejection of extensions in pedantic mode.  */
+/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:1999 -pedantic -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)
+{
+  /* %P is a lowercase version of %p.  */
+  strftime (s, m, "%P", tp); /* { dg-warning "C" "strftime %P" } */
+  /* %k is %H but padded with a space rather than 0 if necessary.  */
+  strftime (s, m, "%k", tp); /* { dg-warning "C" "strftime %k" } */
+  /* %l is %I but padded with a space rather than 0 if necessary.  */
+  strftime (s, m, "%l", tp); /* { dg-warning "C" "strftime %l" } */
+  /* %s is the number of seconds since the Epoch.  */
+  strftime (s, m, "%s", tp); /* { dg-warning "C" "strftime %s" } */
+  /* Extensions using %O already tested in c99-strftime-1.c.  */
+  /* Width and flags are GNU extensions for strftime.  */
+  strftime (s, m, "%20Y", tp); /* { dg-warning "C" "strftime width" } */
+  strftime (s, m, "%^A", tp); /* { dg-warning "C" "strftime flags" } */
+}