diff options
author | Jakub Jelinek <jakub@redhat.com> | 2021-12-10 17:05:04 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2021-12-10 17:05:04 +0100 |
commit | 982a2c9b7866558039df61b0596caad57c94c8c4 (patch) | |
tree | 8613ba3bc90cf1910651da98e5e2239e5d8800b7 /libstdc++-v3/testsuite/22_locale | |
parent | c82e492616e343b6d6db218d2b498267bac899de (diff) | |
download | gcc-982a2c9b7866558039df61b0596caad57c94c8c4.zip gcc-982a2c9b7866558039df61b0596caad57c94c8c4.tar.gz gcc-982a2c9b7866558039df61b0596caad57c94c8c4.tar.bz2 |
libstdc++: Add std::time_get %r support [PR71367]
This incremental patch adds std::time_get %r support (%p was added already
in the previous patch). The _M_am_fm_format method previously in the header
unfortunately had wrong arguments and so was useless, so the largest
complication in this patch is exporting a new symbol in the right symbol
version.
2021-12-10 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/71367
* config/locale/dragonfly/time_members.cc (_M_initialize_timepunct):
Initialize "C" _M_am_pm_format to %I:%M:%S %p rather than empty
string.
* config/locale/gnu/time_members.cc (_M_initialize_timepunct):
Likewise.
* config/locale/generic/time_members.cc (_M_initialize_timepunct):
Likewise.
* include/bits/locale_facets_nonio.h (_M_am_pm_format): New method.
* include/bits/locale_facets_nonio.tcc (_M_extract_via_format): Handle
%r.
* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export _M_am_pm_format
with const _CharT** argument, ensure it isn't exported in GLIBCXX_3.4.
* testsuite/22_locale/time_get/get/char/71367.cc: New test.
* testsuite/22_locale/time_get/get/wchar_t/71367.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/22_locale')
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/time_get/get/char/71367.cc | 67 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71367.cc | 67 |
2 files changed, 134 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get/char/71367.cc b/libstdc++-v3/testsuite/22_locale/time_get/get/char/71367.cc new file mode 100644 index 0000000..b1af4bf --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/time_get/get/char/71367.cc @@ -0,0 +1,67 @@ +// { dg-do run { target c++11 } } + +// Copyright (C) 2021 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <iterator> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + + locale loc_c = locale::classic(); + + istringstream iss; + iss.imbue(loc_c); + const time_get<char>& tget = use_facet<time_get<char>>(iss.getloc()); + typedef istreambuf_iterator<char> iter; + const iter end; + + tm time; + ios_base::iostate err = ios_base::badbit; + + iss.str("01:38:12 PM"); + string format = "%I:%M:%S %p"; + auto ret = tget.get(iter(iss), end, iss, err, &time, + format.data(), format.data()+format.size()); + VERIFY( err == ios_base::eofbit ); + VERIFY( ret == end ); + VERIFY( time.tm_hour == 13 ); + VERIFY( time.tm_min == 38 ); + VERIFY( time.tm_sec == 12 ); + + iss.str("11:17:42 PM"); + format = "%r"; + ret = tget.get(iter(iss), end, iss, err, &time, + format.data(), format.data()+format.size()); + VERIFY( err == ios_base::eofbit ); + VERIFY( ret == end ); + VERIFY( time.tm_hour == 23 ); + VERIFY( time.tm_min == 17 ); + VERIFY( time.tm_sec == 42 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71367.cc b/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71367.cc new file mode 100644 index 0000000..693053e --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/time_get/get/wchar_t/71367.cc @@ -0,0 +1,67 @@ +// { dg-do run { target c++11 } } + +// Copyright (C) 2021 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <iterator> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + + locale loc_c = locale::classic(); + + wistringstream iss; + iss.imbue(loc_c); + const time_get<wchar_t>& tget = use_facet<time_get<wchar_t>>(iss.getloc()); + typedef istreambuf_iterator<wchar_t> iter; + const iter end; + + tm time; + ios_base::iostate err = ios_base::badbit; + + iss.str(L"01:38:12 PM"); + wstring format = L"%I:%M:%S %p"; + auto ret = tget.get(iter(iss), end, iss, err, &time, + format.data(), format.data()+format.size()); + VERIFY( err == ios_base::eofbit ); + VERIFY( ret == end ); + VERIFY( time.tm_hour == 13 ); + VERIFY( time.tm_min == 38 ); + VERIFY( time.tm_sec == 12 ); + + iss.str(L"11:17:42 PM"); + format = L"%r"; + ret = tget.get(iter(iss), end, iss, err, &time, + format.data(), format.data()+format.size()); + VERIFY( err == ios_base::eofbit ); + VERIFY( ret == end ); + VERIFY( time.tm_hour == 23 ); + VERIFY( time.tm_min == 17 ); + VERIFY( time.tm_sec == 42 ); +} + +int +main() +{ + test01(); + return 0; +} |