From: Jonathan Wakely Date: Mon, 10 Aug 2020 11:02:18 +0000 (+0100) Subject: libstdc++: Check __cpp_exceptions in basic_string::reserve() X-Git-Tag: basepoints/gcc-12~5626 X-Git-Url: https://gcc.gnu.org/git/?a=commitdiff_plain;h=8bd92d8097d44be01a2bc7e14f7916d151dffcd6;p=gcc.git libstdc++: Check __cpp_exceptions in basic_string::reserve() If exceptions are disabled then reallocating could abort, so ignore shrink-to-fit requests. libstdc++-v3/ChangeLog: * include/bits/basic_string.tcc [_GLIBCXX_USE_CXX11_ABI=0] (basic_string::reserve()): Do nothing if exceptions are not enabled. --- diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index a64b63a37fbb..95d2fdbd6d6a 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -1179,6 +1179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION basic_string<_CharT, _Traits, _Alloc>:: reserve() { +#if __cpp_exceptions if (length() < capacity() || _M_rep()->_M_is_shared()) try { @@ -1191,6 +1192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { throw; } catch (...) { /* swallow the exception */ } +#endif } template