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.133.124]) by sourceware.org (Postfix) with ESMTPS id DA1F03858C50 for ; Sat, 14 Jan 2023 17:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DA1F03858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673715655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=uADoGoGBJqFf5kbWJKlK1WWYezxcp8RTLRaOYB6ehx4=; b=Y6Vb5Yv2Lv4HaQUEDgHcLKOvbQFNe2oHcIpXL8YcMSpB8MpvG/IBkKv0S6HbxvER6eu1An vI2lxsE0ZOI/WnvuJXiKmdC0PpCKe1+0eve3InDIPvQaAQg3mVpD+WTiBS0/XjMbhLZDrF yRsZGUqpMT8GyIV+KlgQ/CZCKUJ9My0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-cgQhZ1FOObG4v-ANwUlorA-1; Sat, 14 Jan 2023 12:00:37 -0500 X-MC-Unique: cgQhZ1FOObG4v-ANwUlorA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 020EB857A8A; Sat, 14 Jan 2023 17:00:37 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id A154A2026D68; Sat, 14 Jan 2023 17:00:35 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix ostream insertion operators for calendar types Date: Sat, 14 Jan 2023 17:00:35 +0000 Message-Id: <20230114170035.1238643-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux. Pushed to trunk. -- >8 -- libstdc++-v3/ChangeLog: * include/bits/chrono_io.h (operator<<): Fix syntax errors. * testsuite/std/time/month_day/io.cc: New test. * testsuite/std/time/month_day_last/io.cc: New test. * testsuite/std/time/month_weekday/io.cc: New test. * testsuite/std/time/month_weekday_last/io.cc: New test. * testsuite/std/time/weekday_indexed/io.cc: New test. * testsuite/std/time/weekday_last/io.cc: New test. * testsuite/std/time/year_month/io.cc: New test. * testsuite/std/time/year_month_day_last/io.cc: New test. * testsuite/std/time/year_month_weekday/io.cc: New test. * testsuite/std/time/year_month_weekday_last/io.cc: New test. --- libstdc++-v3/include/bits/chrono_io.h | 20 ++++----- .../testsuite/std/time/month_day/io.cc | 30 +++++++++++++ .../testsuite/std/time/month_day_last/io.cc | 30 +++++++++++++ .../testsuite/std/time/month_weekday/io.cc | 31 ++++++++++++++ .../std/time/month_weekday_last/io.cc | 31 ++++++++++++++ .../testsuite/std/time/weekday_indexed/io.cc | 30 +++++++++++++ .../testsuite/std/time/weekday_last/io.cc | 30 +++++++++++++ .../testsuite/std/time/year_month/io.cc | 30 +++++++++++++ .../std/time/year_month_day_last/io.cc | 30 +++++++++++++ .../std/time/year_month_weekday/io.cc | 42 +++++++++++++++++++ .../std/time/year_month_weekday_last/io.cc | 38 +++++++++++++++++ 11 files changed, 332 insertions(+), 10 deletions(-) create mode 100644 libstdc++-v3/testsuite/std/time/month_day/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/month_day_last/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/month_weekday/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/weekday_last/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/year_month/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/year_month_day_last/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/year_month_weekday/io.cc create mode 100644 libstdc++-v3/testsuite/std/time/year_month_weekday_last/io.cc diff --git a/libstdc++-v3/include/bits/chrono_io.h b/libstdc++-v3/include/bits/chrono_io.h index 4e53cd4aa2e..87caa30b83a 100644 --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -2134,7 +2134,7 @@ namespace chrono // either "{:L}[{}]" or "{:L}[{} is not a valid index]". The {:L} spec // means to format the weekday using ostringstream, so just do that. basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __wdi.weekday(); const auto __i = __wdi.index(); if constexpr (is_same_v<_CharT, char>) @@ -2157,7 +2157,7 @@ namespace chrono { // As above, just write straight to a stringstream, as if by "{:L}[last]" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __wdl.weekday() << _GLIBCXX_WIDEN("[last]"); __os << __os2.view(); return __os; @@ -2169,7 +2169,7 @@ namespace chrono { // As above, just write straight to a stringstream, as if by "{:L}/{}" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __md.month(); if constexpr (is_same_v<_CharT, char>) __os2 << '/'; @@ -2189,7 +2189,7 @@ namespace chrono { // As above, just write straight to a stringstream, as if by "{:L}/last" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __mdl.month(); if constexpr (is_same_v<_CharT, char>) __os2 << "/last"; @@ -2206,7 +2206,7 @@ namespace chrono { // As above, just write straight to a stringstream, as if by "{:L}/{:L}" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __mwd.month(); if constexpr (is_same_v<_CharT, char>) __os2 << '/'; @@ -2224,7 +2224,7 @@ namespace chrono { // As above, just write straight to a stringstream, as if by "{:L}/{:L}" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __mwdl.month(); if constexpr (is_same_v<_CharT, char>) __os2 << '/'; @@ -2241,7 +2241,7 @@ namespace chrono { // As above, just write straight to a stringstream, as if by "{}/{:L}" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __ym.year(); if constexpr (is_same_v<_CharT, char>) __os2 << '/'; @@ -2277,7 +2277,7 @@ namespace chrono { // As above, just write straight to a stringstream, as if by "{}/{:L}" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); __os2 << __ymdl.year(); if constexpr (is_same_v<_CharT, char>) __os2 << '/'; @@ -2296,7 +2296,7 @@ namespace chrono // As above, just write straight to a stringstream, as if by // "{}/{:L}/{:L}" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); _CharT __slash; if constexpr (is_same_v<_CharT, char>) __slash = '/'; @@ -2316,7 +2316,7 @@ namespace chrono // As above, just write straight to a stringstream, as if by // "{}/{:L}/{:L}" basic_stringstream<_CharT> __os2; - __os2.imbue(__os.getloc); + __os2.imbue(__os.getloc()); _CharT __slash; if constexpr (is_same_v<_CharT, char>) __slash = '/'; diff --git a/libstdc++-v3/testsuite/std/time/month_day/io.cc b/libstdc++-v3/testsuite/std/time/month_day/io.cc new file mode 100644 index 00000000000..454231dd724 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/month_day/io.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << January/14 << ' ' << February/30 << ' ' << March/34; + VERIFY( ss.str() == "Jan/14 Feb/30 Mar/34 is not a valid day" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << July/27; + VERIFY( ss.str() == "juil./27" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/month_day_last/io.cc b/libstdc++-v3/testsuite/std/time/month_day_last/io.cc new file mode 100644 index 00000000000..6bd95d9d524 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/month_day_last/io.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << January/last << ' ' << February/last << ' ' << March/last; + VERIFY( ss.str() == "Jan/last Feb/last Mar/last" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << July/last; + VERIFY( ss.str() == "juil./last" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/month_weekday/io.cc b/libstdc++-v3/testsuite/std/time/month_weekday/io.cc new file mode 100644 index 00000000000..a62f84a16aa --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/month_weekday/io.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << January/Saturday[2] << ' ' << February/Monday[5] << ' ' + << March/Sunday[8]; + VERIFY( ss.str() == "Jan/Sat[2] Feb/Mon[5] Mar/Sun[8 is not a valid index]" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << July/Thursday[4]; + VERIFY( ss.str() == "juil./jeu.[4]" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc b/libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc new file mode 100644 index 00000000000..f69cc187ce8 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/month_weekday_last/io.cc @@ -0,0 +1,31 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << January/Saturday[last] << ' ' << February/Monday[last] << ' ' + << March/weekday(9)[last]; + VERIFY( ss.str() == "Jan/Sat[last] Feb/Mon[last] Mar/9 is not a valid weekday[last]" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << July/Thursday[last]; + VERIFY( ss.str() == "juil./jeu.[last]" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc b/libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc new file mode 100644 index 00000000000..cdb91f4ba11 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/weekday_indexed/io.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << Monday[2] << ' ' << Wednesday[5] << ' ' << Friday[13]; + VERIFY( ss.str() == "Mon[2] Wed[5] Fri[13 is not a valid index]" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << Saturday[1]; + VERIFY( ss.str() == "sam.[1]" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/weekday_last/io.cc b/libstdc++-v3/testsuite/std/time/weekday_last/io.cc new file mode 100644 index 00000000000..b81830f8f68 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/weekday_last/io.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << Monday[last] << ' ' << Wednesday[last] << ' ' << weekday(9)[last]; + VERIFY( ss.str() == "Mon[last] Wed[last] 9 is not a valid weekday[last]" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << Saturday[last]; + VERIFY( ss.str() == "sam.[last]" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/year_month/io.cc b/libstdc++-v3/testsuite/std/time/year_month/io.cc new file mode 100644 index 00000000000..8c0eb9b6579 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/year_month/io.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << 2023y/January << ' ' << 2023y/month(13); + VERIFY( ss.str() == "2023/Jan 2023/13 is not a valid month" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << 2023y/July; + VERIFY( ss.str() == "2023/juil." ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/year_month_day_last/io.cc b/libstdc++-v3/testsuite/std/time/year_month_day_last/io.cc new file mode 100644 index 00000000000..cb60f078c7e --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/year_month_day_last/io.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << 2023y/January/last << ' ' << 2023y/month(13)/last; + VERIFY( ss.str() == "2023/Jan/last 2023/13 is not a valid month/last" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << 2023y/July/last; + VERIFY( ss.str() == "2023/juil./last" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/year_month_weekday/io.cc b/libstdc++-v3/testsuite/std/time/year_month_weekday/io.cc new file mode 100644 index 00000000000..530429ff129 --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/year_month_weekday/io.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << 2023y/January/Saturday[2]; + VERIFY( ss.str() == "2023/Jan/Sat[2]" ); + ss.clear(); + ss.str(""); + ss << 2023y/month(13)/Monday[1]; + VERIFY( ss.str() == "2023/13 is not a valid month/Mon[1]" ); + ss.clear(); + ss.str(""); + ss << 2023y/December/weekday(9)[5]; + VERIFY( ss.str() == "2023/Dec/9 is not a valid weekday[5]" ); + ss.clear(); + ss.str(""); + ss << 2023y/December/Monday[6]; + VERIFY( ss.str() == "2023/Dec/Mon[6 is not a valid index]" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << 2023y/July/Thursday[2]; + VERIFY( ss.str() == "2023/juil./jeu.[2]" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} diff --git a/libstdc++-v3/testsuite/std/time/year_month_weekday_last/io.cc b/libstdc++-v3/testsuite/std/time/year_month_weekday_last/io.cc new file mode 100644 index 00000000000..f6aff52f7eb --- /dev/null +++ b/libstdc++-v3/testsuite/std/time/year_month_weekday_last/io.cc @@ -0,0 +1,38 @@ +// { dg-options "-std=gnu++20" } +// { dg-do run { target c++20 } } +// { dg-require-namedlocale "fr_FR.ISO8859-15" } + +#include +#include +#include + +void +test_ostream() +{ + using std::ostringstream; + using namespace std::chrono; + + ostringstream ss; + ss << 2023y/January/Monday[last]; + VERIFY( ss.str() == "2023/Jan/Mon[last]" ); + ss.clear(); + ss.str(""); + ss << 2023y/month(13)/Monday[last]; + VERIFY( ss.str() == "2023/13 is not a valid month/Mon[last]" ); + ss.clear(); + ss.str(""); + ss << 2023y/December/weekday(9)[last]; + VERIFY( ss.str() == "2023/Dec/9 is not a valid weekday[last]" ); + + ss.str(""); + ss.imbue(std::locale(ISO_8859(15,fr_FR))); + ss << 2023y/July/Thursday[last]; + VERIFY( ss.str() == "2023/juil./jeu.[last]" ); +} + +int main() +{ + test_ostream(); + // TODO: test_format(); + // TODO: test_parse(); +} -- 2.39.0