[PATCH] Complete __gnu_debug::basic_string
François Dumont
frs.dumont@gmail.com
Sat Mar 20 21:32:58 GMT 2021
Following your feedback here is the simplified version. I grouped it
with the patch I submitted before.
On 19/03/21 8:41 pm, Jonathan Wakely wrote:
> On 16/03/21 21:55 +0100, François Dumont via Libstdc++ wrote:
>> Following:
>>
>> https://gcc.gnu.org/pipermail/libstdc++/2021-March/052158.html
>>
>> Here is the patch to complete __gnu_debug::basic_string support.
>> Contrarily to what I thought code in std::basic_string to generate a
>> basic_string_view works just fine for __gnu_debug::basic_string.
>>
>> libstdc++: [_GLIBCXX_DEBUG] Add __gnu_debug
>> u8string/u16string/u32string
>>
>> Complete __gnu_debug::basic_string support so that it can be used
>> as a
>> transparent replacement of std::basic_string.
>>
>> libstdc++-v3/ChangeLog:
>>
>> * include/debug/string
>> (basic_string(const _CharT*, const _Allocator&)): Remove
>> assign call.
>> (basic_string<>::insert(const_iterator, _InputIte,
>> _InputIte)): Try to
>> remove iterator debug layer even if !_GLIBCXX_USE_CXX11_ABI.
>> [_GLIBCXX_USE_CHAR8_T] (__gnu_debug::u8string): New.
>> (__gnu_debug::u16string, __gnu_debug::u32string): New.
>> [!_GLIBCXX_COMPATIBILITY_CXX0X](std::hash<__gnu_debug::string>): New.
>> [!_GLIBCXX_COMPATIBILITY_CXX0X][_GLIBCXX_USE_WCHAR_T](std::hash<__gnu_debug::wstring>):
>> New.
>> [_GLIBCXX_USE_CHAR8_T](std::hash<__gnu_debug::u8string>): New.
>> (std::hash<__gnu_debug::u16string>): New.
>> (std::hash<__gnu_debug::u32string>): New.
>> * testsuite/21_strings/basic_string/hash/hash_char8_t.cc:
>> Adapt for
>> __gnu_debug basic_string.
>>
>> Tested under Linux x86_64.
>>
>> Ok to commit ?
>>
>> François
>>
>
>> diff --git a/libstdc++-v3/include/debug/string
>> b/libstdc++-v3/include/debug/string
>> index d6eb5280ade..dec23f6277b 100644
>> --- a/libstdc++-v3/include/debug/string
>> +++ b/libstdc++-v3/include/debug/string
>> @@ -41,6 +41,14 @@
>> __gnu_debug::_Error_formatter::_S_at(_File, _Line, _Func) \
>> ._M_message(#_Cond)._M_error()
>>
>> +#if _GLIBCXX_USE_CXX11_ABI && __cplusplus >= 201103
>> +# define _GLIBCXX_CPP11_AND_CXX11_ABI 1
>> +# define _GLIBCXX_CPP11_AND_CXX11_ABI_ONLY(Statement) Statement
>
> This takes an expression, not a statement.
I've been inspired by _GLIBCXX_DEBUG_ONLY
>
> I think it would be better to use more descriptive names for these:
>
> # define _GLIBCXX_INSERT_RETURNS_ITERATOR 1
> # define _GLIBCXX_INSERT_RETURNS_ITERATOR_ONLY(expr) expr
>
> (And don't forget to change the #undef lines too).
>
>> +#if __cplusplus >= 201103L
>> +
>> +namespace std _GLIBCXX_VISIBILITY(default)
>> +{
>> +_GLIBCXX_BEGIN_NAMESPACE_VERSION
>> +
>> + // DR 1182.
>> +
>> +#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
>> + /// std::hash specialization for string.
>> + template<>
>> + struct hash<__gnu_debug::string>
>> + : public __hash_base<size_t, __gnu_debug::string>
>
> I think we could just define on partial specialization that works for
> all cases:
Yes, sounds better. But I relied on std::__hash_base which gives
directly the correct definition.
> Why only make this change for the char8_t version? Why not test
> hash<__gnu_debug::string> as well?
This file also test std::string and so also __gnu_debug::string.
libstdc++: Fix and complete __gnu_debug::basic_string implementation
Fix and complete __gnu_debug::basic_string so that it can be used
as a transparent
replacement of std::basic_string.
libstdc++-v3/ChangeLog:
* include/debug/string
(basic_string(const _CharT*, const _Allocator&)): Remove
assign call.
(basic_string<>::insert(const_iterator, _InputIte,
_InputIte)): Try to
remove iterator debug layer even if !_GLIBCXX_USE_CXX11_ABI.
[_GLIBCXX_USE_CHAR8_T] (__gnu_debug::u8string): New.
(__gnu_debug::u16string, __gnu_debug::u32string): New.
(std::hash<__gnu_debug::basic_string<>>): New partial
specialization.
(std::__is_fast_hash<__gnu_debug::basic_string<>>): Likewise.
(basic_string(const basic_string&, const _Alloc&)): Define
even if !_GLIBCXX_USE_CXX11_ABI.
(basic_string(basic_string&&, const _Alloc&)): Likewise and
add noexcept qualification.
(basic_string<>::erase): Adapt to take __const_iterator.
* testsuite/21_strings/basic_string/hash/debug.cc: New test.
* testsuite/21_strings/basic_string/hash/debug_char8_t.cc:
New test.
*
testsuite/21_strings/basic_string/requirements/citerators.cc: Adapt to
test __gnu_debug::string
when _GLIBCXX_DEBUG is defined.
*
testsuite/21_strings/basic_string/requirements/dr438/constructor.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/exception/basic.cc: Likewise.
*
testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc:
Likewise.
*
testsuite/21_strings/basic_string/requirements/typedefs.cc: Likewise.
* testsuite/util/exception/safety.h
(erase_base<__gnu_debug::basic_string<>>): New partial
specialization.
(insert_base<__gnu_debug::basic_string<>>): Likewise.
* testsuite/util/testsuite_container_traits.h
(traits<__gnu_debug::basic_string<>>): Likewise.
Tested under Linux x86_64.
Ok to commit ?
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: debug_string.patch
Type: text/x-patch
Size: 22680 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210320/3468fcbc/attachment-0001.bin>
More information about the Libstdc++
mailing list