diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9396e227bd1..bfc9319fdd3 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2018-11-19 François Dumont + + * include/ext/throw_allocator.h + (annotate_base::insert(void*, size_t)): Use insert result to check for + double insert attempt. + (annotate_base::insert_construct(void*)): Likewise. + (annotate_base::check_allocated(void*, size_t)): Return found iterator. + (annotate_base::erase(void*, size_t)): Use latter method returned + iterator. + (annotate_base::check_constructed(void*, size_t)): Return found iterator. + (annotate_base::erase_construct(void*)): Use latter method returned + iterator. + 2018-11-19 Ville Voutilainen PR libstdc++/87855 @@ -32,7 +45,7 @@ of the asymptotic series (nu is the Bessel order). * testsuite/tr1/5_numerical_facilities/special_functions/ 09_cyl_bessel_j/check_value.cc: Add tests at nu=100, 1000<=x<=2000. - * testsuite/tr1/5_numerical_facilities/special_functions/ + * testsuite/tr1/5_numerical_facilities/special_functions/ 11_cyl_neumann/check_value.cc: Ditto. * testsuite/special_functions/08_cyl_bessel_j/check_value.cc: Ditto. * testsuite/special_functions/10_cyl_neumann/check_value.cc: Ditto. diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h index dd7c692222e..3a5670e3454 100644 --- a/libstdc++-v3/include/ext/throw_allocator.h +++ b/libstdc++-v3/include/ext/throw_allocator.h @@ -87,6 +87,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ struct annotate_base { + private: + typedef std::pair data_type; + typedef std::map map_alloc_type; + typedef map_alloc_type::value_type entry_type; + typedef map_alloc_type::const_iterator const_iterator; + typedef map_alloc_type::const_reference const_reference; +#if __cplusplus >= 201103L + typedef std::map map_construct_type; +#endif + + public: annotate_base() { label(); @@ -104,31 +115,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void insert(void* p, size_t size) { + entry_type entry = make_entry(p, size); if (!p) { std::string error("annotate_base::insert null insert!\n"); - log_to_string(error, make_entry(p, size)); + log_to_string(error, entry); std::__throw_logic_error(error.c_str()); } - const_iterator found = map_alloc().find(p); - if (found != map_alloc().end()) + std::pair inserted + = map_alloc().insert(entry); + if (!inserted.second) { std::string error("annotate_base::insert double insert!\n"); - log_to_string(error, make_entry(p, size)); - log_to_string(error, *found); + log_to_string(error, entry); + log_to_string(error, *inserted.first); std::__throw_logic_error(error.c_str()); } - - map_alloc().insert(make_entry(p, size)); } void erase(void* p, size_t size) - { - check_allocated(p, size); - map_alloc().erase(p); - } + { map_alloc().erase(check_allocated(p, size)); } #if __cplusplus >= 201103L void @@ -140,31 +148,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION std::__throw_logic_error(error.c_str()); } - auto found = map_construct().find(p); - if (found != map_construct().end()) + auto inserted = map_construct().insert(std::make_pair(p, get_label())); + if (!inserted.second) { std::string error("annotate_base::insert_construct double insert!\n"); log_to_string(error, std::make_pair(p, get_label())); - log_to_string(error, *found); + log_to_string(error, *inserted.first); std::__throw_logic_error(error.c_str()); } - - map_construct().insert(std::make_pair(p, get_label())); } void erase_construct(void* p) - { - check_constructed(p); - map_construct().erase(p); - } + { map_construct().erase(check_constructed(p)); } #endif // See if a particular address and allocation size has been saved. - inline void + inline map_alloc_type::iterator check_allocated(void* p, size_t size) { - const_iterator found = map_alloc().find(p); + map_alloc_type::iterator found = map_alloc().find(p); if (found == map_alloc().end()) { std::string error("annotate_base::check_allocated by value " @@ -181,6 +184,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION log_to_string(error, *found); std::__throw_logic_error(error.c_str()); } + + return found; } // See if a given label has been allocated. @@ -256,7 +261,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #if __cplusplus >= 201103L - inline void + inline map_construct_type::iterator check_constructed(void* p) { auto found = map_construct().find(p); @@ -267,6 +272,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION log_to_string(error, std::make_pair(p, get_label())); std::__throw_logic_error(error.c_str()); } + + return found; } inline void @@ -292,15 +299,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif private: - typedef std::pair data_type; - typedef std::map map_alloc_type; - typedef map_alloc_type::value_type entry_type; - typedef map_alloc_type::const_iterator const_iterator; - typedef map_alloc_type::const_reference const_reference; -#if __cplusplus >= 201103L - typedef std::map map_construct_type; -#endif - friend std::ostream& operator<<(std::ostream&, const annotate_base&);