From: Jonathan Wakely <jwakely@redhat.com>
To: Alexandre Oliva <oliva@adacore.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org,
Corentin Gay <gay@adacore.com>
Subject: Re: Add dg-require-wchars to libstdc++ testsuite#
Date: Thu, 14 Jan 2021 13:47:09 +0000 [thread overview]
Message-ID: <20210114134709.GD7692@redhat.com> (raw)
In-Reply-To: <20210114134142.GC7692@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1336 bytes --]
On 14/01/21 13:41 +0000, Jonathan Wakely wrote:
><aside>
>Is it the case that the wchar_t type is defined on this target, it's
>just that libc doesn't have support for wcslen etc? Because we should
>probably audit all our uses of _GLIBCXX_USE_WCHAR_T and find which
>ones actually need libc support and which just need the wchar_t type
>to exist. Some things really do need the libc support, but I suspect
>many others don't.
>
>It seems wrong that we can provide full support for char16_t and
>char32_t but not wchar_t, just because the former two don't depend on
>anything being present in libc. Why can't we just implement the same
>functionality for wchar_t without using libc?
>
>In fact, if we just define std::char_traits<wchar_t> generically
>without using any libc functions (or just using them as optimisations)
>we might be able to support std::basic_string<wchar_t> and iostream
>classes with almost no work. But that's something to consider in the
>future.
></aside>
Oops, I considered it already.
This untested patch should define std::char_traits<wchar_t> so it is
available if wchar_t is defined by the front end (which I assume is
always true, is that right?), only using optimized libc routines if
available.
This would be the first step to enabling std::wstring etc for targets
with no wchar_t support in libc.
[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 3820 bytes --]
diff --git a/libstdc++-v3/include/bits/char_traits.h b/libstdc++-v3/include/bits/char_traits.h
index ea1e036f721..3a60478ea32 100644
--- a/libstdc++-v3/include/bits/char_traits.h
+++ b/libstdc++-v3/include/bits/char_traits.h
@@ -438,7 +438,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
-#ifdef _GLIBCXX_USE_WCHAR_T
+#ifdef __SIZEOF_WCHAR_T__
/// 21.1.3.2 char_traits specializations
template<>
struct char_traits<wchar_t>
@@ -469,23 +469,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__n == 0)
return 0;
-#if __cplusplus >= 201703L
- if (__builtin_constant_p(__n)
- && __constant_char_array_p(__s1, __n)
- && __constant_char_array_p(__s2, __n))
- return __gnu_cxx::char_traits<char_type>::compare(__s1, __s2, __n);
+#ifdef _GLIBCXX_USE_WCHAR_T
+ if (!__builtin_is_constant_evaluated())
+ return wmemcmp(__s1, __s2, __n);
#endif
- return wmemcmp(__s1, __s2, __n);
+ return __gnu_cxx::char_traits<char_type>::compare(__s1, __s2, __n);
}
static _GLIBCXX17_CONSTEXPR size_t
length(const char_type* __s)
{
-#if __cplusplus >= 201703L
- if (__constant_string_p(__s))
- return __gnu_cxx::char_traits<char_type>::length(__s);
+#ifdef _GLIBCXX_USE_WCHAR_T
+ if (!__builtin_is_constant_evaluated())
+ return wcslen(__s);
#endif
- return wcslen(__s);
+ return __gnu_cxx::char_traits<char_type>::length(__s);
}
static _GLIBCXX17_CONSTEXPR const char_type*
@@ -493,13 +491,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__n == 0)
return 0;
-#if __cplusplus >= 201703L
- if (__builtin_constant_p(__n)
- && __builtin_constant_p(__a)
- && __constant_char_array_p(__s, __n))
- return __gnu_cxx::char_traits<char_type>::find(__s, __n, __a);
+#ifdef _GLIBCXX_USE_WCHAR_T
+ if (!__builtin_is_constant_evaluated())
+ return wmemchr(__s, __a, __n);
#endif
- return wmemchr(__s, __a, __n);
+ return __gnu_cxx::char_traits<char_type>::find(__s, __n, __a);
}
static _GLIBCXX20_CONSTEXPR char_type*
@@ -507,11 +503,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__n == 0)
return __s1;
-#ifdef __cpp_lib_is_constant_evaluated
- if (std::is_constant_evaluated())
- return __gnu_cxx::char_traits<char_type>::move(__s1, __s2, __n);
+#ifdef _GLIBCXX_USE_WCHAR_T
+ if (!__builtin_is_constant_evaluated())
+ return wmemmove(__s1, __s2, __n);
#endif
- return wmemmove(__s1, __s2, __n);
+ return __gnu_cxx::char_traits<char_type>::move(__s1, __s2, __n);
}
static _GLIBCXX20_CONSTEXPR char_type*
@@ -519,11 +515,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__n == 0)
return __s1;
-#ifdef __cpp_lib_is_constant_evaluated
- if (std::is_constant_evaluated())
- return __gnu_cxx::char_traits<char_type>::copy(__s1, __s2, __n);
+#ifdef _GLIBCXX_USE_WCHAR_T
+ if (!__builtin_is_constant_evaluated())
+ return wmemcpy(__s1, __s2, __n);
#endif
- return wmemcpy(__s1, __s2, __n);
+ return __gnu_cxx::char_traits<char_type>::copy(__s1, __s2, __n);
}
static _GLIBCXX20_CONSTEXPR char_type*
@@ -531,11 +527,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
if (__n == 0)
return __s;
-#ifdef __cpp_lib_is_constant_evaluated
- if (std::is_constant_evaluated())
- return __gnu_cxx::char_traits<char_type>::assign(__s, __n, __a);
+#ifdef _GLIBCXX_USE_WCHAR_T
+ if (!__builtin_is_constant_evaluated())
+ return wmemset(__s, __a, __n);
#endif
- return wmemset(__s, __a, __n);
+ return __gnu_cxx::char_traits<char_type>::assign(__s, __n, __a);
}
static _GLIBCXX_CONSTEXPR char_type
@@ -558,7 +554,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT
{ return eq_int_type(__c, eof()) ? 0 : __c; }
};
-#endif //_GLIBCXX_USE_WCHAR_T
+#endif // __SIZEOF_WCHAR_T__
#ifdef _GLIBCXX_USE_CHAR8_T
template<>
next prev parent reply other threads:[~2021-01-14 13:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-22 21:12 Add dg-require-wchars to libstdc++ testsuite Alexandre Oliva
2020-12-28 18:23 ` François Dumont
2021-01-13 17:29 ` Alexandre Oliva
2021-01-14 13:08 ` Jonathan Wakely
2020-12-28 18:27 ` François Dumont
2021-01-14 13:41 ` Jonathan Wakely
2021-01-14 13:47 ` Jonathan Wakely [this message]
2021-01-14 22:20 ` Alexandre Oliva
2021-01-15 10:09 ` Jonathan Wakely
2021-01-15 16:18 ` Alexandre Oliva
2021-01-15 19:47 ` Jonathan Wakely
2021-10-09 7:31 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210114134709.GD7692@redhat.com \
--to=jwakely@redhat.com \
--cc=gay@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
--cc=oliva@adacore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).