re PR libstdc++/86272 (__gnu_debug::string uses undefined __glibcxx_check_insert_range2)

2018-07-04  François Dumont  <fdumont@gcc.gnu.org>

	PR libstdc++/86272
	* include/debug/string
	(__gnu_debug::basic_string<>::insert<_Ite>(const_iterator, _Ite, _Ite)):
	Use __glibcxx_check_insert_range.
	* 21_strings/basic_string/cons/char/1.cc: Adapt test to use
	__gnu_debug::string when _GLIBCXX_DEBUG.
	* 21_strings/basic_string/init-list.cc: Likewise.
	* 21_strings/basic_string/modifiers/insert/char/1.cc: Likewise.
	* 21_strings/basic_string/modifiers/insert/char/2.cc: Likewise.
	* 21_strings/basic_string/modifiers/insert/char/83328.cc: Likewise.
	* 21_strings/basic_string/types/1.cc: Likewise.

From-SVN: r262417
This commit is contained in:
François Dumont 2018-07-04 18:13:11 +00:00
parent fa9371cae0
commit 96eb9df619
8 changed files with 85 additions and 34 deletions

View File

@ -1,3 +1,16 @@
2018-07-03 François Dumont <fdumont@gcc.gnu.org>
* include/debug/string
(__gnu_debug::basic_string<>::insert<_Ite>(const_iterator, _Ite, _Ite)):
Use __glibcxx_check_insert_range.
* 21_strings/basic_string/cons/char/1.cc: Adapt test to use
__gnu_debug::string when _GLIBCXX_DEBUG.
* 21_strings/basic_string/init-list.cc: Likewise.
* 21_strings/basic_string/modifiers/insert/char/1.cc: Likewise.
* 21_strings/basic_string/modifiers/insert/char/2.cc: Likewise.
* 21_strings/basic_string/modifiers/insert/char/83328.cc: Likewise.
* 21_strings/basic_string/types/1.cc: Likewise.
2018-07-04 Jonathan Wakely <jwakely@redhat.com>
* testsuite/25_algorithms/make_heap/complexity.cc: Require effective

View File

@ -566,7 +566,7 @@ template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
insert(const_iterator __p, _InputIterator __first, _InputIterator __last)
{
typename __gnu_debug::_Distance_traits<_InputIterator>::__type __dist;
__glibcxx_check_insert_range2(__p, __first, __last, __dist);
__glibcxx_check_insert_range(__p, __first, __last, __dist);
typename _Base::iterator __res;
if (__dist.second >= __dp_sign)

View File

@ -20,25 +20,32 @@
// 21.3.1 basic_string constructors.
#include <new>
#include <string>
#include <stdexcept>
#include <testsuite_hooks.h>
#ifdef _GLIBCXX_DEBUG
# include <debug/string>
using namespace __gnu_debug;
#else
# include <string>
using namespace std;
#endif
void test01(void)
{
typedef std::string::size_type csize_type;
typedef std::string::iterator citerator;
csize_type npos = std::string::npos;
typedef string::size_type csize_type;
typedef string::iterator citerator;
csize_type npos = string::npos;
csize_type csz01;
const char str_lit01[] = "rodeo beach, marin";
const std::string str01(str_lit01);
const std::string str02("baker beach, san francisco");
const string str01(str_lit01);
const string str02("baker beach, san francisco");
// basic_string(const string&, size_type pos = 0, siz_type n = npos, alloc)
csz01 = str01.size();
try {
std::string str03(str01, csz01 + 1);
string str03(str01, csz01 + 1);
VERIFY( false );
}
catch(std::out_of_range& fail) {
@ -49,7 +56,7 @@ void test01(void)
}
try {
std::string str03(str01, csz01);
string str03(str01, csz01);
VERIFY( str03.size() == 0 );
VERIFY( str03.size() <= str03.capacity() );
}
@ -62,7 +69,7 @@ void test01(void)
// NB: As strlen(str_lit01) != csz01, this test is undefined. It
// should not crash, but what gets constructed is a bit arbitrary.
try {
std::string str03(str_lit01, csz01 + 1);
string str03(str_lit01, csz01 + 1);
VERIFY( true );
}
catch(std::length_error& fail) {
@ -76,7 +83,7 @@ void test01(void)
// should not crash, but what gets constructed is a bit arbitrary.
// The "maverick's" of all string objects.
try {
std::string str04(str_lit01, npos);
string str04(str_lit01, npos);
VERIFY( true );
}
catch(std::length_error& fail) {
@ -88,7 +95,7 @@ void test01(void)
// Build a maxsize - 1 lengthed string consisting of all A's
try {
std::string str03(csz01 - 1, 'A');
string str03(csz01 - 1, 'A');
VERIFY( str03.size() == csz01 - 1 );
VERIFY( str03.size() <= str03.capacity() );
}
@ -102,14 +109,14 @@ void test01(void)
}
// basic_string(const char* s, const allocator& a = allocator())
std::string str04(str_lit01);
string str04(str_lit01);
VERIFY( str01 == str04 );
// basic_string(size_type n, char c, const allocator& a = allocator())
csz01 = str01.max_size();
try {
std::string str03(csz01 + 1, 'z');
string str03(csz01 + 1, 'z');
VERIFY( false );
}
catch(std::length_error& fail) {
@ -120,7 +127,7 @@ void test01(void)
}
try {
std::string str04(npos, 'b'); // the "maverick's" of all string objects.
string str04(npos, 'b'); // the "maverick's" of all string objects.
VERIFY( false );
}
catch(std::length_error& fail) {
@ -131,7 +138,7 @@ void test01(void)
}
try {
std::string str03(csz01 - 1, 'z');
string str03(csz01 - 1, 'z');
VERIFY( str03.size() != 0 );
VERIFY( str03.size() <= str03.capacity() );
}
@ -144,10 +151,9 @@ void test01(void)
VERIFY( false );
}
// template<typename _InputIter>
// basic_string(_InputIter begin, _InputIter end, const allocator& a)
std::string str06(str01.begin(), str01.end());
string str06(str01.begin(), str01.end());
VERIFY( str06 == str01 );
}

View File

@ -18,10 +18,15 @@
// { dg-do run { target c++11 } }
#include <string>
#include <testsuite_hooks.h>
#ifdef _GLIBCXX_DEBUG
#include <debug/string>
using namespace __gnu_debug;
#else
#include <string>
using namespace std;
#endif
void test01(void)
{

View File

@ -19,19 +19,26 @@
// 21.3.5.4 basic_string::insert
#include <string>
#include <stdexcept>
#include <testsuite_hooks.h>
#ifdef _GLIBCXX_DEBUG
#include <debug/string>
using namespace __gnu_debug;
#else
#include <string>
using namespace std;
#endif
void test01(void)
{
typedef std::string::size_type csize_type;
typedef std::string::iterator citerator;
typedef string::size_type csize_type;
typedef string::iterator citerator;
csize_type csz01, csz02;
const std::string str01("rodeo beach, marin");
const std::string str02("baker beach, san francisco");
std::string str03;
const string str01("rodeo beach, marin");
const string str02("baker beach, san francisco");
string str03;
// string& insert(size_type p1, const string& str, size_type p2, size_type n)
// requires:
@ -76,7 +83,7 @@ void test01(void)
csz01 = str01.max_size();
try {
std::string str04(csz01, 'b');
string str04(csz01, 'b');
str03 = str04;
csz02 = str02.size();
try {

View File

@ -19,16 +19,23 @@
// 21.3.5.4 basic_string::insert
#include <string>
#include <testsuite_hooks.h>
#ifdef _GLIBCXX_DEBUG
#include <debug/string>
using namespace __gnu_debug;
#else
#include <string>
using namespace std;
#endif
// More
// string& insert(size_type __p, const char* s, size_type n);
// string& insert(size_type __p, const char* s);
// but now s points inside the _Rep
void test02(void)
{
std::string str01;
string str01;
const char* title = "Everything was beautiful, and nothing hurt";
// Increasing size: str01 is reallocated every time.
str01 = title;

View File

@ -20,18 +20,25 @@
// PR libstdc++/83328
#include <string>
#include <testsuite_hooks.h>
#ifdef _GLIBCXX_DEBUG
#include <debug/string>
using namespace __gnu_debug;
#else
#include <string>
using namespace std;
#endif
void
test01()
{
std::string s = "insert";
string s = "insert";
auto iter = s.insert(s.cbegin() + 2, std::initializer_list<char>{});
VERIFY( iter == s.begin() + 2 );
iter = s.insert(s.cend(), { 'e', 'd' });
std::string::iterator* check_type = &iter;
string::iterator* check_type = &iter;
VERIFY( iter == s.cend() - 2 );
VERIFY( s == "inserted" );

View File

@ -19,7 +19,13 @@
// { dg-do compile }
#include <string>
#if _GLIBCXX_DEBUG
# include <debug/string>
using namespace __gnu_debug;
#else
# include <string>
using namespace std;
#endif
namespace N
{
@ -36,7 +42,7 @@ namespace N
int main()
{
std::basic_string<N::X> s(5, N::X());
basic_string<N::X> s(5, N::X());
s.erase(s.begin());
s.erase(s.begin(), s.end());