* [PATCH] Fix __gnu_debug::basic_string
@ 2021-03-08 21:04 François Dumont
0 siblings, 0 replies; only message in thread
From: François Dumont @ 2021-03-08 21:04 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 2233 bytes --]
__gnu_debug::basic_string is not extensively used nor extensively tested
so not actively maintained.
So here is a first patch to fix some problems and increase test
coverage. I plan another patch cause I think it is missing some C++17
methods.
Tested under Linux x86_64, ok to commit ?
libstdc++: Fix __gnu_debug::basic_string<> and adapt tests
libstdc++-v3/ChangeLog:
* include/debug/string
(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/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
* testsuite/util/testsuite_container_traits.h
François
[-- Attachment #2: debug_string.patch --]
[-- Type: text/x-patch, Size: 15311 bytes --]
diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string
index 172179530aa..d6eb5280ade 100644
--- a/libstdc++-v3/include/debug/string
+++ b/libstdc++-v3/include/debug/string
@@ -123,21 +123,21 @@ namespace __gnu_debug
using _Base::npos;
- basic_string()
- _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_default_constructible<_Base>::value)
- : _Base() { }
-
// 21.3.1 construct/copy/destroy:
+
explicit
basic_string(const _Allocator& __a) _GLIBCXX_NOEXCEPT
: _Base(__a) { }
#if __cplusplus < 201103L
+ basic_string() : _Base() { }
+
basic_string(const basic_string& __str)
: _Base(__str) { }
~basic_string() { }
#else
+ basic_string() = default;
basic_string(const basic_string&) = default;
basic_string(basic_string&&) = default;
@@ -146,13 +146,15 @@ namespace __gnu_debug
: _Base(__l, __a)
{ }
-#if _GLIBCXX_USE_CXX11_ABI
basic_string(const basic_string& __s, const _Allocator& __a)
: _Base(__s, __a) { }
basic_string(basic_string&& __s, const _Allocator& __a)
- : _Base(std::move(__s), __a) { }
-#endif
+ noexcept( noexcept(
+ _Base(std::declval<_Base>()), std::declval<const _Allocator&>()) )
+ : _Safe(std::move(__s._M_safe()), __a),
+ _Base(std::move(__s._M_base()), __a)
+ { }
~basic_string() = default;
@@ -676,7 +678,7 @@ namespace __gnu_debug
}
iterator
- erase(iterator __position)
+ erase(__const_iterator __position)
{
__glibcxx_check_erase(__position);
typename _Base::iterator __res = _Base::erase(__position.base());
@@ -685,7 +687,7 @@ namespace __gnu_debug
}
iterator
- erase(iterator __first, iterator __last)
+ erase(__const_iterator __first, __const_iterator __last)
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 151. can't currently clear() empty container
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc
index 99bf5726dcc..69d4a8d0e51 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc
@@ -18,14 +18,21 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
#include <testsuite_containers.h>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
int main()
{
- __gnu_test::citerator<std::string> test1;
+ __gnu_test::citerator<string> test1;
#ifdef _GLIBCXX_USE_WCHAR_T
- __gnu_test::citerator<std::wstring> test2;
+ __gnu_test::citerator<wstring> test2;
#endif
return 0;
}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc
index 82d42ebb6a6..104fd653642 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/dr438/constructor.cc
@@ -19,9 +19,17 @@
// { dg-do compile }
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+
+using namespace __gnu_debug;
+#else
+# include <string>
+
+using namespace std;
+#endif
void f()
{
- std::string s(10, 1);
+ string s(10, 1);
}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc
index 2b6e27432e8..f40dda2b5bc 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/basic.cc
@@ -20,9 +20,16 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
#include <exception/safety.h>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
void
value()
{
@@ -31,7 +38,7 @@ value()
typedef char value_type;
typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type;
typedef std::char_traits<value_type> traits_type;
- typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+ typedef basic_string<value_type, traits_type, allocator_type> test_type;
__gnu_test::basic_safety<test_type> test;
}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc
index 07d2a2e2074..dc9bdb298ae 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/generation_prohibited.cc
@@ -20,16 +20,23 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
#include <exception/safety.h>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
void
char_allocator()
{
typedef char value_type;
typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type;
typedef std::char_traits<value_type> traits_type;
- typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+ typedef basic_string<value_type, traits_type, allocator_type> test_type;
__gnu_test::generation_prohibited<test_type> test;
}
@@ -39,7 +46,7 @@ wchar_allocator()
typedef wchar_t value_type;
typedef __gnu_cxx::throw_allocator_random<value_type> allocator_type;
typedef std::char_traits<value_type> traits_type;
- typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+ typedef basic_string<value_type, traits_type, allocator_type> test_type;
__gnu_test::generation_prohibited<test_type> test;
}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc
index ce99dab915e..818c487c9c9 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/exception/propagation_consistent.cc
@@ -20,9 +20,16 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
#include <exception/safety.h>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
+
void
value()
{
@@ -31,7 +38,7 @@ value()
typedef char value_type;
typedef __gnu_cxx::throw_allocator_limit<value_type> allocator_type;
typedef std::char_traits<value_type> traits_type;
- typedef std::basic_string<value_type, traits_type, allocator_type> test_type;
+ typedef basic_string<value_type, traits_type, allocator_type> test_type;
__gnu_test::propagation_consistent<test_type> test;
}
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc
index 275354c1f4c..6910933253a 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char/1.cc
@@ -17,6 +17,12 @@
// along with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
-template class std::basic_string<char>;
+template class basic_string<char>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc
index 2b5139de533..aadb9ef580c 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char16_t/1.cc
@@ -17,6 +17,12 @@
// along with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
-template class std::basic_string<char16_t>;
+template class basic_string<char16_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc
index 0fa685e9094..62760f7180f 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char32_t/1.cc
@@ -17,6 +17,12 @@
// along with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
-template class std::basic_string<char32_t>;
+template class basic_string<char32_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc
index db88b0f47a3..c38f31429da 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/char8_t/1.cc
@@ -18,6 +18,12 @@
// along with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
-template class std::basic_string<char8_t>;
+template class basic_string<char8_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc
index 7f16ca4cb5b..a0565baee54 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/explicit_instantiation/wchar_t/1.cc
@@ -17,6 +17,12 @@
// along with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include <string>
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+using namespace __gnu_debug;
+#else
+# include <string>
+using namespace std;
+#endif
-template class std::basic_string<wchar_t>;
+template class basic_string<wchar_t>;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc
index 2fc313b9cbf..b90eb020db4 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/requirements/typedefs.cc
@@ -18,10 +18,19 @@
// <http://www.gnu.org/licenses/>.
#include <testsuite_containers.h>
-#include <string>
+
+#ifdef _GLIBCXX_DEBUG
+# include <debug/string>
+
+using namespace __gnu_debug;
+#else
+# include <string>
+
+using namespace std;
+#endif
// Check container for required typedefs.
-__gnu_test::types<std::string> t1;
+__gnu_test::types<string> t1;
#ifdef _GLIBCXX_USE_WCHAR_T
-__gnu_test::types<std::wstring> t2;
+__gnu_test::types<wstring> t2;
#endif
diff --git a/libstdc++-v3/testsuite/util/exception/safety.h b/libstdc++-v3/testsuite/util/exception/safety.h
index 6c91e740e0d..9309af15405 100644
--- a/libstdc++-v3/testsuite/util/exception/safety.h
+++ b/libstdc++-v3/testsuite/util/exception/safety.h
@@ -266,6 +266,20 @@ namespace __gnu_test
iterator (container_type::* _F_erase_point)(iterator);
iterator (container_type::* _F_erase_range)(iterator, iterator);
+ erase_base()
+ : _F_erase_point(&container_type::erase),
+ _F_erase_range(&container_type::erase) { }
+ };
+
+ template<typename _Tp1, typename _Tp2, typename _Tp3>
+ struct erase_base<__gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>>
+ {
+ typedef __gnu_debug::basic_string<_Tp1, _Tp2, _Tp3> container_type;
+ typedef typename container_type::iterator iterator;
+
+ iterator (container_type::* _F_erase_point)(iterator);
+ iterator (container_type::* _F_erase_range)(iterator, iterator);
+
erase_base()
: _F_erase_point(&container_type::erase),
_F_erase_range(&container_type::erase) { }
@@ -681,6 +695,24 @@ namespace __gnu_test
typedef typename container_type::const_iterator const_iterator;
typedef typename container_type::value_type value_type;
+#if _GLIBCXX_USE_CXX11_ABI == 0 || __cplusplus < 201103L
+ iterator (container_type::* _F_insert_point)(iterator, value_type);
+#else
+ iterator (container_type::* _F_insert_point)(const_iterator,
+ value_type);
+#endif
+
+ insert_base() : _F_insert_point(&container_type::insert) { }
+ };
+
+ template<typename _Tp1, typename _Tp2, typename _Tp3>
+ struct insert_base<__gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>>
+ {
+ typedef __gnu_debug::basic_string<_Tp1, _Tp2, _Tp3> container_type;
+ typedef typename container_type::iterator iterator;
+ typedef typename container_type::const_iterator const_iterator;
+ typedef typename container_type::value_type value_type;
+
#if _GLIBCXX_USE_CXX11_ABI == 0 || __cplusplus < 201103L
iterator (container_type::* _F_insert_point)(iterator, value_type);
#else
diff --git a/libstdc++-v3/testsuite/util/testsuite_container_traits.h b/libstdc++-v3/testsuite/util/testsuite_container_traits.h
index fb1f558011c..0bc7a2aa53a 100644
--- a/libstdc++-v3/testsuite/util/testsuite_container_traits.h
+++ b/libstdc++-v3/testsuite/util/testsuite_container_traits.h
@@ -22,6 +22,7 @@
#include <bits/stdc++.h>
#include <ext/vstring.h>
+#include <debug/string>
namespace __gnu_test
{
@@ -128,6 +129,17 @@ namespace __gnu_test
typedef std::true_type has_insert;
};
+ template<typename _Tp1, typename _Tp2, typename _Tp3>
+ struct traits<__gnu_debug::basic_string<_Tp1, _Tp2, _Tp3>> : public traits_base
+ {
+ typedef std::true_type is_container;
+ typedef std::true_type is_reversible;
+ typedef std::true_type is_allocator_aware;
+
+ typedef std::true_type has_erase;
+ typedef std::true_type has_insert;
+ };
+
template<typename _Tp1, typename _Tp2, typename _Tp3,
template <typename, typename, typename> class _Tp4>
struct traits<__gnu_cxx::__versa_string<_Tp1, _Tp2, _Tp3, _Tp4>>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-03-08 21:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 21:04 [PATCH] Fix __gnu_debug::basic_string François Dumont
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).