public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5165] libstdc++: Fix ostream insertion operators for calendar types
@ 2023-01-14 17:00 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2023-01-14 17:00 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:9afc914809ca90d03a9a8f53c439ebf4c62cf544
commit r13-5165-g9afc914809ca90d03a9a8f53c439ebf4c62cf544
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sat Jan 14 15:41:58 2023 +0000
libstdc++: Fix ostream insertion operators for calendar types
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.
Diff:
---
libstdc++-v3/include/bits/chrono_io.h | 20 +++++------
libstdc++-v3/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 ++++++++++++++++
.../testsuite/std/time/month_weekday_last/io.cc | 31 ++++++++++++++++
.../testsuite/std/time/weekday_indexed/io.cc | 30 ++++++++++++++++
libstdc++-v3/testsuite/std/time/weekday_last/io.cc | 30 ++++++++++++++++
libstdc++-v3/testsuite/std/time/year_month/io.cc | 30 ++++++++++++++++
.../testsuite/std/time/year_month_day_last/io.cc | 30 ++++++++++++++++
.../testsuite/std/time/year_month_weekday/io.cc | 42 ++++++++++++++++++++++
.../std/time/year_month_weekday_last/io.cc | 38 ++++++++++++++++++++
11 files changed, 332 insertions(+), 10 deletions(-)
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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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 <chrono>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+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();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-14 17:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-14 17:00 [gcc r13-5165] libstdc++: Fix ostream insertion operators for calendar types Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).