libstdc++: Fix src/c++20/format.cc for non-gthreads targets

libstdc++-v3/ChangeLog:

	* src/c++20/format.cc [!_GLIBCXX_HAS_GTHREADS] (mutex): Define
	dummy mutex type.
	* testsuite/std/time/format_localized.cc: Use loop variable
	instead of creating the same locale on every iteration.
This commit is contained in:
Jonathan Wakely
2024-07-31 20:27:33 +01:00
committed by Jonathan Wakely
parent 6886f1c164
commit e7d88ff8aa
2 changed files with 14 additions and 5 deletions

View File

@@ -49,6 +49,15 @@ namespace __format
#if defined _GLIBCXX_USE_NL_LANGINFO_L && __CHAR_BIT__ == 8
namespace
{
#ifndef _GLIBCXX_HAS_GTHREADS
// Dummy mutex
struct mutex
{
void lock() const { }
void unlock() const { }
};
#endif
// A non-standard locale::facet that caches the locale's std::text_encoding
// and an iconv descriptor for converting from that encoding to UTF-8.
struct __encoding : locale::facet
@@ -59,7 +68,7 @@ struct __encoding : locale::facet
__encoding(const text_encoding& enc, size_t refs = 0)
: facet(refs), _M_enc(enc)
{
#if defined _GLIBCXX_HAVE_ICONV
#ifdef _GLIBCXX_HAVE_ICONV
using enum text_encoding::id;
switch (_M_enc.mib())
{
@@ -74,14 +83,14 @@ struct __encoding : locale::facet
~__encoding()
{
#if defined _GLIBCXX_HAVE_ICONV
#ifdef _GLIBCXX_HAVE_ICONV
if (_M_cd != (::iconv_t)-1)
::iconv_close(_M_cd);
#endif
}
text_encoding _M_enc;
#if defined _GLIBCXX_HAVE_ICONV
#ifdef _GLIBCXX_HAVE_ICONV
::iconv_t _M_cd = (::iconv_t)-1;
mutable mutex mx;
#endif
@@ -93,7 +102,7 @@ struct __encoding : locale::facet
if (input.empty()) [[unlikely]]
return codecvt_base::noconv;
#if defined _GLIBCXX_HAVE_ICONV
#ifdef _GLIBCXX_HAVE_ICONV
if (_M_cd == (::iconv_t)-1)
return codecvt_base::error;

View File

@@ -75,7 +75,7 @@ test_en()
for (auto l : {ISO_8859(1,en_US), ISO_8859(15,en_US), "en_US.UTF-8", "C"})
{
std::locale loc(ISO_8859(1,en_US));
std::locale loc(l);
auto s = std::format(loc, "{:L%b %B %a %A}", sys_days(2024y/July/30));
VERIFY( s == "Jul July Tue Tuesday" );
}