From 99f04955edfdff11e3270df6326f426a29e1ec5a Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 17 Sep 2015 15:56:46 +0100 Subject: [PATCH] Only do shrink_to_fit() when exceptions enabled * include/bits/allocator.h (__shrink_to_fit_aux::_S_do_it): Do nothing if exceptions are disabled. * include/bits/basic_string.h (basic_string::shrink_to_fit): Likewise. From-SVN: r227870 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/bits/allocator.h | 8 ++++++-- libstdc++-v3/include/bits/basic_string.h | 12 ++++++++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b8c11843632..2bcfa161fcf 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2015-09-17 Jonathan Wakely + + * include/bits/allocator.h (__shrink_to_fit_aux::_S_do_it): + Do nothing if exceptions are disabled. + * include/bits/basic_string.h (basic_string::shrink_to_fit): Likewise. + 2015-09-16 Jonathan Wakely PR libstdc++/67173 diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 6fd3214cd02..0131521c5cd 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -209,15 +209,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static bool _S_do_it(_Tp& __c) noexcept { - __try +#if __cpp_exceptions + try { _Tp(__make_move_if_noexcept_iterator(__c.begin()), __make_move_if_noexcept_iterator(__c.end()), __c.get_allocator()).swap(__c); return true; } - __catch(...) + catch(...) { return false; } +#else + return false; +#endif } }; #endif diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index e6e7bb525ba..b5e7e3628c6 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -833,13 +833,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 void shrink_to_fit() noexcept { +#if __cpp_exceptions if (capacity() > size()) { - __try + try { reserve(0); } - __catch(...) + catch(...) { } } +#endif } #endif @@ -3282,12 +3284,14 @@ _GLIBCXX_END_NAMESPACE_CXX11 void shrink_to_fit() _GLIBCXX_NOEXCEPT { +#if __cpp_exceptions if (capacity() > size()) { - __try + try { reserve(0); } - __catch(...) + catch(...) { } +#endif } } #endif -- 2.30.2