+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>
* acinclude.m4 (GLIBCPP_CHECK_WCHAR_T_SUPPORT): Check for wctype.h.
{
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())
return _S_empty_rep()._M_refcopy();
template<typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>::
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>
// 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
// software; you can redistribute it and/or modify it under the
#include <stdexcept>
#include <testsuite_hooks.h>
-int test01(void)
+void test01(void)
{
bool test = true;
typedef std::string::size_type csize_type;
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)
csz01 = str01.max_size();
// NB: As strlen(str_lit01) != csz01, this test is undefined. It
catch(...) {
VERIFY( false );
}
-#endif
// basic_string(const char* s, const allocator& a = allocator())
std::string str04(str_lit01);
// basic_string(_InputIter begin, _InputIter end, const allocator& a)
std::string str06(str01.begin(), str01.end());
VERIFY( str06 == str01 );
-
-#ifdef DEBUG_ASSERT
- assert(test);
-#endif
- return test;
}
void test02()
// where _InputIter is integral [21.3.1 para 15]
std::string s(10,0);
VERIFY( s.size() == 10 );
-#ifdef DEBUG_ASSERT
- assert(test);
-#endif
}
void test03()
std::string s2 (s1);
VERIFY( s2.size() == 28 );
-#ifdef DEBUG_ASSERT
- assert(test);
-#endif
+ // Not defined, but libstdc++ throws an exception.
+ const char* bogus = 0;
+ 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()