When exceptions are disabled a failed allocation while trying to
shrink_to_fit() will abort the program. Since shrink_to_fit() is a
non-binding request we should just ignore it rather than risk taking
down the whole process.

Tested powerpc64le-linux, committed to trunk.


commit 13cf19282acf42a52d5eacd2c293a944bd3e5ebe
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Sep 17 00:07:33 2015 +0100

    Only do shrink_to_fit() when exceptions enabled
    
    	* include/bits/allocator.h (__shrink_to_fit_aux<T, true>::_S_do_it):
    	Do nothing if exceptions are disabled.
    	* include/bits/basic_string.h (basic_string::shrink_to_fit): Likewise.

diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h
index 6fd3214..0131521 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 e6e7bb5..b5e7e36 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

Reply via email to