From: Jonathan Wakely <jwakely@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: [committed] libstdc++: Enforce value_type consistency in strings and streams
Date: Fri, 12 May 2023 00:29:48 +0100 [thread overview]
Message-ID: <CACb0b4np-CAwfS9SD=fNdB5U38nakSou06tggsj1aGnbwacE7w@mail.gmail.com> (raw)
In-Reply-To: <20230511201847.1056247-1-jwakely@redhat.com>
[-- Attachment #1.1: Type: text/plain, Size: 501 bytes --]
On Thu, 11 May 2023 at 21:20, Jonathan Wakely via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:
> Tested powerpc64le-linux. Pushed to trunk.
>
> I don't plan to backport the assertions, because they're an API change
> that isn't suitable for the branches. But removing _Alloc_traits_impl
> and replacing it with _S_allocate should be done for gcc-13 to keep the
> contents of the two libstdc++.so.6.0.32 libraries in sync.
>
>
Here's the gcc-13 backport. No new assertions, just the new exported symbol.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6265 bytes --]
commit 0d5a359140503d26adf11325e1f9a09ba7067dfc
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed May 10 21:30:10 2023
libstdc++: Backport std::basic_string::_S_allocate from trunk
This is a backport of r14-739-gc62e945492afbb to keep the exported
symbol list consistent between trunk and gcc-13. The new assertions from
that commit are not part of this backport.
libstdc++-v3/ChangeLog:
* config/abi/pre/gnu.ver: Export basic_string::_S_allocate.
* include/bits/basic_string.h: (basic_string::_Alloc_traits_impl):
Remove class template.
(basic_string::_S_allocate): New static member function.
(basic_string::assign): Use _S_allocate.
* include/bits/basic_string.tcc (basic_string::_M_create)
(basic_string::reserve, basic_string::_M_replace): Likewise.
(cherry picked from commit c62e945492afbbd2a09896fc7b0b07f7e719a606)
diff --git a/libstdc++-v3/config/abi/pre/gnu.ver b/libstdc++-v3/config/abi/pre/gnu.ver
index 36bb87880d7..768cd4a4a6c 100644
--- a/libstdc++-v3/config/abi/pre/gnu.ver
+++ b/libstdc++-v3/config/abi/pre/gnu.ver
@@ -1759,7 +1759,9 @@ GLIBCXX_3.4.21 {
#endif
# ABI-tagged std::basic_string
- _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE1[01]**;
+ _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE10_M_[dr]*;
+ _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE10_S_compareE[jmy][jmy];
+ _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE11_M_capacityE[jmy];
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_Alloc_hiderC[12]EP[cw]RKS3_;
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE12_M*;
_ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE13*;
@@ -2516,6 +2518,7 @@ GLIBCXX_3.4.31 {
GLIBCXX_3.4.32 {
_ZSt21ios_base_library_initv;
+ _ZNSt7__cxx1112basic_stringI[cw]St11char_traitsI[cw]ESaI[cw]EE11_S_allocateERS3_[jmy];
} GLIBCXX_3.4.31;
# Symbols in the support library (libsupc++) have their own tag.
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index b16b2898b62..870b4728928 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -89,36 +89,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
rebind<_CharT>::other _Char_alloc_type;
-#if __cpp_lib_constexpr_string < 201907L
typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits;
-#else
- template<typename _Traits2, typename _Dummy_for_PR85282>
- struct _Alloc_traits_impl : __gnu_cxx::__alloc_traits<_Char_alloc_type>
- {
- typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Base;
-
- [[__gnu__::__always_inline__]]
- static constexpr typename _Base::pointer
- allocate(_Char_alloc_type& __a, typename _Base::size_type __n)
- {
- pointer __p = _Base::allocate(__a, __n);
- if (std::is_constant_evaluated())
- // Begin the lifetime of characters in allocated storage.
- for (size_type __i = 0; __i < __n; ++__i)
- std::construct_at(__builtin_addressof(__p[__i]));
- return __p;
- }
- };
-
- template<typename _Dummy_for_PR85282>
- struct _Alloc_traits_impl<char_traits<_CharT>, _Dummy_for_PR85282>
- : __gnu_cxx::__alloc_traits<_Char_alloc_type>
- {
- // std::char_traits begins the lifetime of characters.
- };
-
- using _Alloc_traits = _Alloc_traits_impl<_Traits, void>;
-#endif
// Types:
public:
@@ -149,6 +120,22 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
#endif
private:
+ static _GLIBCXX20_CONSTEXPR pointer
+ _S_allocate(_Char_alloc_type& __a, size_type __n)
+ {
+ pointer __p = _Alloc_traits::allocate(__a, __n);
+#if __cpp_lib_constexpr_string >= 201907L
+ // std::char_traits begins the lifetime of characters,
+ // but custom traits might not, so do it here.
+ if constexpr (!is_same_v<_Traits, char_traits<_CharT>>)
+ if (std::__is_constant_evaluated())
+ // Begin the lifetime of characters in allocated storage.
+ for (size_type __i = 0; __i < __n; ++__i)
+ std::construct_at(__builtin_addressof(__p[__i]));
+#endif
+ return __p;
+ }
+
#if __cplusplus >= 201703L
// A helper type for avoiding boiler-plate.
typedef basic_string_view<_CharT, _Traits> __sv_type;
@@ -1596,7 +1583,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
const auto __len = __str.size();
auto __alloc = __str._M_get_allocator();
// If this allocation throws there are no effects:
- auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1);
+ auto __ptr = _S_allocate(__alloc, __len + 1);
_M_destroy(_M_allocated_capacity);
_M_data(__ptr);
_M_capacity(__len);
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc
index 99fdbeee5ad..d8a279fc9ed 100644
--- a/libstdc++-v3/include/bits/basic_string.tcc
+++ b/libstdc++-v3/include/bits/basic_string.tcc
@@ -152,7 +152,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// NB: Need an array of char_type[__capacity], plus a terminating
// null char_type() element.
- return _Alloc_traits::allocate(_M_get_allocator(), __capacity + 1);
+ return _S_allocate(_M_get_allocator(), __capacity + 1);
}
// NB: This is the special case for Input Iterators, used in
@@ -376,8 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
else if (__length < __capacity)
try
{
- pointer __tmp
- = _Alloc_traits::allocate(_M_get_allocator(), __length + 1);
+ pointer __tmp = _S_allocate(_M_get_allocator(), __length + 1);
this->_S_copy(__tmp, _M_data(), __length + 1);
_M_dispose();
_M_data(__tmp);
@@ -521,8 +520,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cpp_lib_is_constant_evaluated
if (std::is_constant_evaluated())
{
- auto __newp = _Alloc_traits::allocate(_M_get_allocator(),
- __new_size);
+ auto __newp = _S_allocate(_M_get_allocator(), __new_size);
_S_copy(__newp, this->_M_data(), __pos);
_S_copy(__newp + __pos, __s, __len2);
_S_copy(__newp + __pos + __len2, __p + __len1, __how_much);
prev parent reply other threads:[~2023-05-11 23:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-11 20:18 Jonathan Wakely
2023-05-11 23:29 ` Jonathan Wakely [this message]
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='CACb0b4np-CAwfS9SD=fNdB5U38nakSou06tggsj1aGnbwacE7w@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/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).