https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71367

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
   Target Milestone|---                         |10.0
           Severity|minor                       |normal

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We need this to fix some failing tests now, because glibc 2.29 changed T_FMT
for some locales, including en_HK which we use in:

testsuite/22_locale/time_get/get_time/char/2.cc
testsuite/22_locale/time_get/get_time/wchar_t/2.cc

They fail because the %X format is now "%I:%M:%S %p %Z".

This patch allows %p to match "AM" or "PM", but locales are allowed to define
their own strings instead of those:

diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.h
b/libstdc++-v3/include/bits/locale_facets_nonio.h
index 8247cfd0bc9..ef395d990e3 100644
--- a/libstdc++-v3/include/bits/locale_facets_nonio.h
+++ b/libstdc++-v3/include/bits/locale_facets_nonio.h
@@ -60,6 +60,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       // List of all known timezones, with GMT first.
       static const _CharT*             _S_timezones[14];
+      static const _CharT*             _S_ampm[2];

       const _CharT*                    _M_date_format;
       const _CharT*                    _M_date_era_format;
diff --git a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
index 9c80e5d751b..2fe0bb91f93 100644
--- a/libstdc++-v3/include/bits/locale_facets_nonio.tcc
+++ b/libstdc++-v3/include/bits/locale_facets_nonio.tcc
@@ -760,6 +760,18 @@ _GLIBCXX_END_NAMESPACE_LDBL_OR_CXX11
                  else
                    __tmperr |= ios_base::failbit;
                  break;
+               case 'p':
+                 {
+                   int __tmp;
+                   __beg = _M_extract_name(__beg, __end, __tmp,
+                                      __timepunct_cache<_CharT>::_S_ampm, 2,
+                                           __io, __tmperr);
+                   if (__tmp == 0 && __tm->tm_hour == 12)
+                     __tm->tm_hour = 0; // "12:34:56 AM" is "00:34:56s"
+                   if (__tmp == 1 && __tm->tm_hour < 12)
+                     __tm->tm_hour += 12; // "11:22:33 PM" is "23:22:33"
+                 }
+                 break;
                case 'R':
                  // Equivalent to (%H:%M).
                  __cs = "%H:%M";
diff --git a/libstdc++-v3/src/c++98/locale_facets.cc
b/libstdc++-v3/src/c++98/locale_facets.cc
index 051396a1468..0b769e9bb0c 100644
--- a/libstdc++-v3/src/c++98/locale_facets.cc
+++ b/libstdc++-v3/src/c++98/locale_facets.cc
@@ -36,6 +36,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       "IST", "EET", "CST", "JST"
     };

+  template<>
+    const char*
+    __timepunct_cache<char>::_S_ampm[2] = { "AM", "PM" };
+
 #ifdef _GLIBCXX_USE_WCHAR_T
   template<>
     const wchar_t*
@@ -44,6 +48,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       L"GMT", L"HST", L"AKST", L"PST", L"MST", L"CST", L"EST", L"AST",
       L"NST", L"CET", L"IST", L"EET", L"CST", L"JST"
     };
+
+  template<>
+    const wchar_t*
+    __timepunct_cache<wchar_t>::_S_ampm[2] = { L"AM", L"PM" };
 #endif

   // Definitions for static const data members of money_base.

The patch is also incomplete because the new static variables get exported with
the wrong symbol version.

Reply via email to