From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 16D733858C39 for ; Tue, 14 Dec 2021 23:38:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16D733858C39 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-5WEWG5cmM3SSxS2vI34yng-1; Tue, 14 Dec 2021 18:38:01 -0500 X-MC-Unique: 5WEWG5cmM3SSxS2vI34yng-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CCAB101AFA7; Tue, 14 Dec 2021 23:38:00 +0000 (UTC) Received: from localhost (unknown [10.33.36.71]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1430A84A0D; Tue, 14 Dec 2021 23:37:59 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Support old and new T_FMT for en_HK locale [PR103687] Date: Tue, 14 Dec 2021 23:37:59 +0000 Message-Id: <20211214233759.2177884-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_BODY, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Dec 2021 23:38:07 -0000 Tested x86_64-linux (glibc 2.33) and powerpc64le-linux (glibc 2.17). Pushed to trunk. This checks whether the locale data for en_HK includes %p and adjusts the string being tested accordingly. To account for Jakub's fix to make %I parse "12" as 0 instead of 12, we need to change the expected value for the case where the locale format doesn't include %p. Also change the time from 12:00:00 to 12:02:01 so we can tell if the minutes and seconds get mixed up. libstdc++-v3/ChangeLog: PR libstdc++/103687 * testsuite/22_locale/time_get/get_date/wchar_t/4.cc: Restore original locale before returning. * testsuite/22_locale/time_get/get_time/char/2.cc: Check for %p in locale's T_FMT and adjust accordingly. * testsuite/22_locale/time_get/get_time/wchar_t/2.cc: Likewise. --- .../22_locale/time_get/get_date/wchar_t/4.cc | 9 ++--- .../22_locale/time_get/get_time/char/2.cc | 33 +++++++++++++++++-- .../22_locale/time_get/get_time/wchar_t/2.cc | 33 +++++++++++++++++-- 3 files changed, 65 insertions(+), 10 deletions(-) diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_date/wchar_t/4.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_date/wchar_t/4.cc index d227d4b1ce0..f6de882e4bd 100644 --- a/libstdc++-v3/testsuite/22_locale/time_get/get_date/wchar_t/4.cc +++ b/libstdc++-v3/testsuite/22_locale/time_get/get_date/wchar_t/4.cc @@ -39,7 +39,7 @@ void test01() wistringstream iss; iss.imbue(loc_tw); - const time_get& tim_get = use_facet >(iss.getloc()); + const time_get& tim_get = use_facet >(iss.getloc()); const ios_base::iostate good = ios_base::goodbit; ios_base::iostate errorstate = good; @@ -66,13 +66,14 @@ void test01() static bool debian_date_format() { #ifdef D_FMT + std::string orig = setlocale(LC_TIME, NULL); if (setlocale(LC_TIME, "zh_TW.UTF-8") != NULL) { // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31413 // and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71641#c2 - if (*nl_langinfo(D_FMT) == '%') - return true; - setlocale(LC_TIME, "C"); + std::string d_fmt = nl_langinfo(D_FMT); + setlocale(LC_TIME, orig.c_str()); + return d_fmt[0] == '%'; } #endif return false; diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_time/char/2.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_time/char/2.cc index a847748dc27..b40971a9bf7 100644 --- a/libstdc++-v3/testsuite/22_locale/time_get/get_time/char/2.cc +++ b/libstdc++-v3/testsuite/22_locale/time_get/get_time/char/2.cc @@ -25,6 +25,8 @@ #include #include +static bool ampm_time_format(); + void test02() { using namespace std; @@ -36,19 +38,23 @@ void test02() locale loc_hk = locale(ISO_8859(1,en_HK)); VERIFY( loc_hk != loc_c ); + const int pm = ampm_time_format() ? 12 : 0; const string empty; - const tm time_bday = __gnu_test::test_tm(0, 0, 12, 4, 3, 71, 0, 93, 0); + const tm time_bday = __gnu_test::test_tm(1, 2, 0+pm, 4, 3, 71, 0, 93, 0); // create an ostream-derived object, cache the time_get facet iterator_type end; istringstream iss; - const time_get& tim_get = use_facet >(iss.getloc()); + const time_get& tim_get = use_facet >(iss.getloc()); const ios_base::iostate good = ios_base::goodbit; ios_base::iostate errorstate = good; // inspection of named locales, en_HK iss.imbue(loc_hk); - iss.str("12:00:00 PM PST"); + if (pm) + iss.str("12:02:01 PM PST"); + else + iss.str("12:02:01 PST"); // %I means 12-hour clock, so parsed as 12am // Hong Kong in California! Well, they have Paris in Vegas... this // is all a little disney-esque anyway. Besides, you can get decent // Dim Sum in San Francisco. @@ -62,6 +68,27 @@ void test02() VERIFY( errorstate == ios_base::eofbit ); } +#include +#if __has_include() +# include +#endif +#include + +static bool ampm_time_format() +{ +#ifdef T_FMT + std::string orig = setlocale(LC_TIME, NULL); + if (setlocale(LC_TIME, ISO_8859(1,en_HK)) != NULL) + { + // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103687 + std::string t_fmt = nl_langinfo(T_FMT); + setlocale(LC_TIME, orig.c_str()); + return t_fmt.find("%p") != std::string::npos; + } +#endif + return false; +} + int main() { test02(); diff --git a/libstdc++-v3/testsuite/22_locale/time_get/get_time/wchar_t/2.cc b/libstdc++-v3/testsuite/22_locale/time_get/get_time/wchar_t/2.cc index b5d61e1afdb..b74604ef472 100644 --- a/libstdc++-v3/testsuite/22_locale/time_get/get_time/wchar_t/2.cc +++ b/libstdc++-v3/testsuite/22_locale/time_get/get_time/wchar_t/2.cc @@ -25,6 +25,8 @@ #include #include +static bool ampm_time_format(); + void test02() { using namespace std; @@ -36,19 +38,23 @@ void test02() locale loc_hk = locale(ISO_8859(1,en_HK)); VERIFY( loc_hk != loc_c ); + const int pm = ampm_time_format() ? 12 : 0; const wstring empty; - const tm time_bday = __gnu_test::test_tm(0, 0, 12, 4, 3, 71, 0, 93, 0); + const tm time_bday = __gnu_test::test_tm(1, 2, 0+pm, 4, 3, 71, 0, 93, 0); // create an ostream-derived object, cache the time_get facet iterator_type end; wistringstream iss; - const time_get& tim_get = use_facet >(iss.getloc()); + const time_get& tim_get = use_facet >(iss.getloc()); const ios_base::iostate good = ios_base::goodbit; ios_base::iostate errorstate = good; // inspection of named locales, en_HK iss.imbue(loc_hk); - iss.str(L"12:00:00 PM PST"); + if (pm) + iss.str(L"12:02:01 PM PST"); + else + iss.str(L"12:02:01 PST"); // %I means 12-hour clock, so parsed as 12am // Hong Kong in California! Well, they have Paris in Vegas... this // is all a little disney-esque anyway. Besides, you can get decent // Dim Sum in San Francisco. @@ -62,6 +68,27 @@ void test02() VERIFY( errorstate == ios_base::eofbit ); } +#include +#if __has_include() +# include +#endif +#include + +static bool ampm_time_format() +{ +#ifdef T_FMT + std::string orig = setlocale(LC_TIME, NULL); + if (setlocale(LC_TIME, ISO_8859(1,en_HK)) != NULL) + { + // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103687 + std::string t_fmt = nl_langinfo(T_FMT); + setlocale(LC_TIME, orig.c_str()); + return t_fmt.find("%p") != std::string::npos; + } +#endif + return false; +} + int main() { test02(); -- 2.31.1