Fixed error in default_init_allocator, it should not construct objects, only allocate raw memory.

[SVN r85999]
This commit is contained in:
Ion Gaztañaga
2013-09-29 11:39:34 +00:00
parent 232e18956a
commit 59c5ed7781
2 changed files with 5 additions and 13 deletions

View File

@@ -11,14 +11,6 @@
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
#include <boost/detail/no_exceptions_support.hpp> #include <boost/detail/no_exceptions_support.hpp>
// TODO: Disable parts of the unit test that should not run when BOOST_NO_EXCEPTIONS
// if exceptions are enabled there must be a user defined throw_exception function
#ifdef BOOST_NO_EXCEPTIONS
namespace boost {
void throw_exception(std::exception const &){}; // user defined
} // namespace boost
#endif // BOOST_NO_EXCEPTIONS
#include <vector> #include <vector>
#include <list> #include <list>

View File

@@ -78,9 +78,9 @@ class default_init_allocator
T* allocate(std::size_t n) T* allocate(std::size_t n)
{ {
//Initialize memory to a pattern //Initialize memory to a pattern
T *const p = ::new T[n]; const std::size_t max = sizeof(T)*n;
unsigned char *puc_raw = reinterpret_cast<unsigned char*>(p); unsigned char *puc_raw = ::new unsigned char[max];
std::size_t max = sizeof(T)*n;
if(base_t::s_ascending){ if(base_t::s_ascending){
for(std::size_t i = 0; i != max; ++i){ for(std::size_t i = 0; i != max; ++i){
puc_raw[i] = static_cast<unsigned char>(s_pattern++); puc_raw[i] = static_cast<unsigned char>(s_pattern++);
@@ -91,11 +91,11 @@ class default_init_allocator
puc_raw[i] = static_cast<unsigned char>(s_pattern--); puc_raw[i] = static_cast<unsigned char>(s_pattern--);
} }
} }
return p; return (T*)puc_raw;;
} }
void deallocate(T *p, std::size_t) void deallocate(T *p, std::size_t)
{ delete[] p; } { delete[] (unsigned char*)p; }
}; };
template<class T> template<class T>