aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-10-04 22:56:14 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2019-10-04 22:56:14 +0100
commit843f104d5bc6d1f9b4b3f56c3a4e4278e608827f (patch)
treeea451e764d55e6941bf945e7254076fc1e531b97 /gcc
parentdaa94de24b9afdf21c636532e53561aa3713910b (diff)
downloadgcc-843f104d5bc6d1f9b4b3f56c3a4e4278e608827f.zip
gcc-843f104d5bc6d1f9b4b3f56c3a4e4278e608827f.tar.gz
gcc-843f104d5bc6d1f9b4b3f56c3a4e4278e608827f.tar.bz2
Add strftime format checking support for C2x %OB and %Ob (bug 82752).
C2x adds strftime %OB and %Ob formats, for alternative forms of month names (for mainly Slavic languages where a month name on its own is declined differently from a month name together with a date within that month). This patch adds corresponding format checking support. (glibc support for these formats was added in glibc 2.27.) Bootstrapped with no regressions on x86_64-pc-linux-gnu. PR c/82752 gcc/c-family: * c-format.c (C_STD_VER): Handle C2x. (C_STD_NAME): Likewise. (strftime_flag_specs): Add 'O' modifier with 'p' flag. (time_char_table): Use separate entry for 'B' and 'b', with 'O' modifier allowed and 'p' flag. * c-format.h (enum format_std_version): Add STD_C2X. (struct format_char_info): Mention 'p' in comment on flags2. gcc/testsuite: * gcc.dg/format/c2x-strftime-1.c: New test. From-SVN: r276605
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/ChangeLog11
-rw-r--r--gcc/c-family/c-format.c16
-rw-r--r--gcc/c-family/c-format.h2
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/format/c2x-strftime-1.c15
5 files changed, 44 insertions, 5 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 0eade3c..1ebc4d9 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,14 @@
+2019-10-04 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/82752
+ * c-format.c (C_STD_VER): Handle C2x.
+ (C_STD_NAME): Likewise.
+ (strftime_flag_specs): Add 'O' modifier with 'p' flag.
+ (time_char_table): Use separate entry for 'B' and 'b', with 'O'
+ modifier allowed and 'p' flag.
+ * c-format.h (enum format_std_version): Add STD_C2X.
+ (struct format_char_info): Mention 'p' in comment on flags2.
+
2019-10-01 David Malcolm <dmalcolm@redhat.com>
* c-opts.c (c_diagnostic_finalizer): Temporarily clear prefix when
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 91bae3d..3c291ca 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -404,9 +404,11 @@ decode_format_attr (const_tree fntype, tree atname, tree args,
/* The C standard version we are checking formats against when pedantic. */
#define C_STD_VER ((int) (c_dialect_cxx () \
? CPLUSPLUS_STD_VER \
- : (flag_isoc99 \
- ? STD_C99 \
- : (flag_isoc94 ? STD_C94 : STD_C89))))
+ : (flag_isoc2x \
+ ? STD_C2X \
+ : (flag_isoc99 \
+ ? STD_C99 \
+ : (flag_isoc94 ? STD_C94 : STD_C89)))))
/* The name to give to the standard version we are warning about when
pedantic. FEATURE_VER is the version in which the feature warned out
appeared, which is higher than C_STD_VER. */
@@ -415,7 +417,9 @@ decode_format_attr (const_tree fntype, tree atname, tree args,
: "ISO C++11") \
: ((FEATURE_VER) == STD_EXT \
? "ISO C" \
- : "ISO C90"))
+ : ((FEATURE_VER) == STD_C2X \
+ ? "ISO C17" \
+ : "ISO C90")))
/* Adjust a C standard version, which may be STD_C9L, to account for
-Wno-long-long. Returns other standard versions unchanged. */
#define ADJ_STD(VER) ((int) ((VER) == STD_C9L \
@@ -653,6 +657,7 @@ static const format_flag_spec strftime_flag_specs[] =
{ 'E', 0, 0, 0, N_("'E' modifier"), N_("the 'E' strftime modifier"), STD_C99 },
{ 'O', 0, 0, 0, N_("'O' modifier"), N_("the 'O' strftime modifier"), STD_C99 },
{ 'O', 'o', 0, 0, NULL, N_("the 'O' modifier"), STD_EXT },
+ { 'O', 'p', 0, 0, NULL, N_("the 'O' modifier"), STD_C2X },
{ 0, 0, 0, 0, NULL, NULL, STD_C89 }
};
@@ -887,7 +892,8 @@ static const format_char_info scan_char_table[] =
static const format_char_info time_char_table[] =
{
/* C89 conversion specifiers. */
- { "ABZab", 0, STD_C89, NOLENGTHS, "^#", "", NULL },
+ { "AZa", 0, STD_C89, NOLENGTHS, "^#", "", NULL },
+ { "Bb", 0, STD_C89, NOLENGTHS, "O^#", "p", NULL },
{ "cx", 0, STD_C89, NOLENGTHS, "E", "3", NULL },
{ "HIMSUWdmw", 0, STD_C89, NOLENGTHS, "-_0Ow", "", NULL },
{ "j", 0, STD_C89, NOLENGTHS, "-_0Ow", "o", NULL },
diff --git a/gcc/c-family/c-format.h b/gcc/c-family/c-format.h
index 6aa68df..15a3153 100644
--- a/gcc/c-family/c-format.h
+++ b/gcc/c-family/c-format.h
@@ -48,6 +48,7 @@ enum format_std_version
STD_C94,
STD_C9L, /* C99, but treat as C89 if -Wno-long-long. */
STD_C99,
+ STD_C2X,
STD_EXT
};
@@ -149,6 +150,7 @@ struct format_char_info
two digit year formats, "3" for strftime formats giving two digit
years in some locales, "4" for "2" which becomes "3" with an "E" modifier,
"o" if use of strftime "O" is a GNU extension beyond C99,
+ "p" if use of strftime "O" is a C2x feature,
"W" if the argument is a pointer which is dereferenced and written into,
"R" if the argument is a pointer which is dereferenced and read from,
"i" for printf integer formats where the '0' flag is ignored with
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d8987ca..4624521 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-10-04 Joseph Myers <joseph@codesourcery.com>
+
+ PR c/82752
+ * gcc.dg/format/c2x-strftime-1.c: New test.
+
2019-10-04 Martin Sebor <msebor@redhat.com>
PR middle-end/91977
diff --git a/gcc/testsuite/gcc.dg/format/c2x-strftime-1.c b/gcc/testsuite/gcc.dg/format/c2x-strftime-1.c
new file mode 100644
index 0000000..c6e7619
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/format/c2x-strftime-1.c
@@ -0,0 +1,15 @@
+/* Test for strftime formats. Formats using C2x features. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x -pedantic -Wformat" } */
+
+#include "format.h"
+
+void
+foo (char *s, size_t m, const struct tm *tp)
+{
+ strftime (s, m, "%Ob", tp);
+ strftime (s, m, "%OB", tp);
+ /* It's not clear that %h equivalence to %b means %Oh is equivalent
+ to %Ob; here we expect %Oh to be diagnosed. */
+ strftime (s, m, "%Oh", tp); /* { dg-warning "flag|modifier" "bad %Oh" } */
+}