basic_string.tcc (string::_S_construct(_InIter, _InIter, const _Alloc&, forward_iterator_tag): Check for null.
2002-03-12 Benjamin Kosnik <bkoz@redhat.com> * include/bits/basic_string.tcc (string::_S_construct(_InIter, _InIter, const _Alloc&, forward_iterator_tag): Check for null. (string::basic_string(const _CharT* __s, const _Alloc& __a)): Same. * testsuite/21_strings/ctor_copy_dtor.cc (test01): Re-enable, now that memory limits are in place. (test03): Add tests. From-SVN: r50683
This commit is contained in:
parent
6a45951fb2
commit
fcaa810173
3 changed files with 39 additions and 18 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2002-03-12 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
|
* include/bits/basic_string.tcc (string::_S_construct(_InIter,
|
||||||
|
_InIter, const _Alloc&, forward_iterator_tag): Check for null.
|
||||||
|
(string::basic_string(const _CharT* __s, const _Alloc& __a)): Same.
|
||||||
|
* testsuite/21_strings/ctor_copy_dtor.cc (test01): Re-enable, now
|
||||||
|
that memory limits are in place.
|
||||||
|
(test03): Add tests.
|
||||||
|
|
||||||
2002-03-11 Benjamin Kosnik <bkoz@redhat.com>
|
2002-03-11 Benjamin Kosnik <bkoz@redhat.com>
|
||||||
|
|
||||||
* acinclude.m4 (GLIBCPP_CHECK_WCHAR_T_SUPPORT): Check for wctype.h.
|
* acinclude.m4 (GLIBCPP_CHECK_WCHAR_T_SUPPORT): Check for wctype.h.
|
||||||
|
|
|
@ -139,6 +139,10 @@ namespace std
|
||||||
{
|
{
|
||||||
size_type __dnew = static_cast<size_type>(distance(__beg, __end));
|
size_type __dnew = static_cast<size_type>(distance(__beg, __end));
|
||||||
|
|
||||||
|
// NB: Not required, but considered best practice.
|
||||||
|
if (__builtin_expect(__beg == _InIter(0), 0))
|
||||||
|
__throw_logic_error("attempt to create string with null pointer");
|
||||||
|
|
||||||
if (__beg == __end && __a == _Alloc())
|
if (__beg == __end && __a == _Alloc())
|
||||||
return _S_empty_rep()._M_refcopy();
|
return _S_empty_rep()._M_refcopy();
|
||||||
|
|
||||||
|
@ -219,7 +223,8 @@ namespace std
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
basic_string<_CharT, _Traits, _Alloc>::
|
basic_string<_CharT, _Traits, _Alloc>::
|
||||||
basic_string(const _CharT* __s, const _Alloc& __a)
|
basic_string(const _CharT* __s, const _Alloc& __a)
|
||||||
: _M_dataplus(_S_construct(__s, __s + traits_type::length(__s), __a), __a)
|
: _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) : 0,
|
||||||
|
__a), __a)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template<typename _CharT, typename _Traits, typename _Alloc>
|
template<typename _CharT, typename _Traits, typename _Alloc>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// 1999-06-04 bkoz
|
// 1999-06-04 bkoz
|
||||||
|
|
||||||
// Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
|
// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||||
//
|
//
|
||||||
// This file is part of the GNU ISO C++ Library. This library is free
|
// This file is part of the GNU ISO C++ Library. This library is free
|
||||||
// software; you can redistribute it and/or modify it under the
|
// software; you can redistribute it and/or modify it under the
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <testsuite_hooks.h>
|
#include <testsuite_hooks.h>
|
||||||
|
|
||||||
int test01(void)
|
void test01(void)
|
||||||
{
|
{
|
||||||
bool test = true;
|
bool test = true;
|
||||||
typedef std::string::size_type csize_type;
|
typedef std::string::size_type csize_type;
|
||||||
|
@ -59,9 +59,6 @@ int test01(void)
|
||||||
VERIFY( false );
|
VERIFY( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// XXX These tests have been temporarily disabled.
|
|
||||||
//http://gcc.gnu.org/ml/libstdc++/2000-10/msg00033.html
|
|
||||||
// basic_string(const char* s, size_type n, alloc)
|
// basic_string(const char* s, size_type n, alloc)
|
||||||
csz01 = str01.max_size();
|
csz01 = str01.max_size();
|
||||||
// NB: As strlen(str_lit01) != csz01, this test is undefined. It
|
// NB: As strlen(str_lit01) != csz01, this test is undefined. It
|
||||||
|
@ -105,7 +102,6 @@ int test01(void)
|
||||||
catch(...) {
|
catch(...) {
|
||||||
VERIFY( false );
|
VERIFY( false );
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// basic_string(const char* s, const allocator& a = allocator())
|
// basic_string(const char* s, const allocator& a = allocator())
|
||||||
std::string str04(str_lit01);
|
std::string str04(str_lit01);
|
||||||
|
@ -155,11 +151,6 @@ int test01(void)
|
||||||
// basic_string(_InputIter begin, _InputIter end, const allocator& a)
|
// basic_string(_InputIter begin, _InputIter end, const allocator& a)
|
||||||
std::string str06(str01.begin(), str01.end());
|
std::string str06(str01.begin(), str01.end());
|
||||||
VERIFY( str06 == str01 );
|
VERIFY( str06 == str01 );
|
||||||
|
|
||||||
#ifdef DEBUG_ASSERT
|
|
||||||
assert(test);
|
|
||||||
#endif
|
|
||||||
return test;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test02()
|
void test02()
|
||||||
|
@ -171,9 +162,6 @@ void test02()
|
||||||
// where _InputIter is integral [21.3.1 para 15]
|
// where _InputIter is integral [21.3.1 para 15]
|
||||||
std::string s(10,0);
|
std::string s(10,0);
|
||||||
VERIFY( s.size() == 10 );
|
VERIFY( s.size() == 10 );
|
||||||
#ifdef DEBUG_ASSERT
|
|
||||||
assert(test);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test03()
|
void test03()
|
||||||
|
@ -189,9 +177,28 @@ void test03()
|
||||||
std::string s2 (s1);
|
std::string s2 (s1);
|
||||||
VERIFY( s2.size() == 28 );
|
VERIFY( s2.size() == 28 );
|
||||||
|
|
||||||
#ifdef DEBUG_ASSERT
|
// Not defined, but libstdc++ throws an exception.
|
||||||
assert(test);
|
const char* bogus = 0;
|
||||||
#endif
|
try
|
||||||
|
{
|
||||||
|
std::string str1(bogus);
|
||||||
|
VERIFY( false );
|
||||||
|
}
|
||||||
|
catch(std::exception& fail)
|
||||||
|
{
|
||||||
|
VERIFY( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not defined, but libstdc++ throws an exception.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string str2(bogus, 5);
|
||||||
|
VERIFY( false );
|
||||||
|
}
|
||||||
|
catch(std::exception& fail)
|
||||||
|
{
|
||||||
|
VERIFY( true );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue