libstdc++: Make testsuite usable with -fno-exceptions
authorJonathan Wakely <jwakely@redhat.com>
Thu, 30 Jul 2020 11:23:54 +0000 (12:23 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 30 Jul 2020 11:50:02 +0000 (12:50 +0100)
Previously it was not possible to add -fno-exceptions to the testsuite
flags, because some files that are compiled by the v3-build_support
procedure failed with exceptions disabled.

This adjusts those files to still compile without exceptions (with
degraded functionality in some cases).

The sole testcase that explicitly checks for -fno-exceptions has also
been adjusted to use the more robust exceptions_enabled effective-target
keyword from gcc/testsuite/lib/target-supports.exp.

libstdc++-v3/ChangeLog:

* testsuite/23_containers/vector/bool/72847.cc: Use the
exceptions_enabled effective-target keyword instead of
checking for an explicit -fno-exceptions option.
* testsuite/util/testsuite_abi.cc (examine_symbol): Remove
redundant try-catch.
* testsuite/util/testsuite_allocator.h [!__cpp_exceptions]:
Do not define check_allocate_max_size and memory_resource.
* testsuite/util/testsuite_containers.h: Replace comment with
#error if wrong standard dialect used.
* testsuite/util/testsuite_shared.cc: Likewise.

libstdc++-v3/testsuite/23_containers/vector/bool/72847.cc
libstdc++-v3/testsuite/util/testsuite_abi.cc
libstdc++-v3/testsuite/util/testsuite_allocator.h
libstdc++-v3/testsuite/util/testsuite_containers.h
libstdc++-v3/testsuite/util/testsuite_shared.cc

index 26260e762afe64d91e712322e9c8aa86d9981d58..c4fbc75abe84d8cf301d067ba6176f9cdbacb64e 100644 (file)
@@ -15,7 +15,7 @@
 // with this library; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
-// { dg-skip-if "" { *-*-* } { "-fno-exceptions" } }
+// { dg-require-effective-target exceptions_enabled }
 
 #include <vector>
 #include <ext/throw_allocator.h>
index fd8224b6789d23ad428ebd80a9fff16527bd5ade..f4bd319855a05b0043094332d64874404df60479 100644 (file)
@@ -362,14 +362,9 @@ get_symbol(const string& name, const symbols& s)
 void
 examine_symbol(const char* name, const char* file)
 {
-  try
-    {
-      symbols s = create_symbols(file);
-      const symbol& sym = get_symbol(name, s);
-      sym.print();
-    }
-  catch(...)
-    { __throw_exception_again; }
+    symbols s = create_symbols(file);
+    const symbol& sym = get_symbol(name, s);
+    sym.print();
 }
 
 int
index e52ef7884679a58092f2fefd329bb51469f31f51..e030ed5500c1c1671e65472a90be30723b5a1586 100644 (file)
@@ -257,6 +257,7 @@ namespace __gnu_test
       return true;
     }
 
+#if __cpp_exceptions
   template<typename Alloc>
     bool
     check_allocate_max_size()
@@ -276,6 +277,7 @@ namespace __gnu_test
        }
       throw;
     }
+#endif
 
   // A simple allocator which can be constructed endowed of a given
   // "personality" (an integer), queried in operator== to simulate the
@@ -761,7 +763,7 @@ namespace __gnu_test
 #endif // C++11
 
 #if __cplusplus >= 201703L
-#if __cpp_aligned_new && __cpp_rtti
+#if __cpp_aligned_new && __cpp_rtti && __cpp_exceptions
   // A concrete memory_resource, with error checking.
   class memory_resource : public std::pmr::memory_resource
   {
index 8566af17c4a3ab154aa10e5984aa9331dcb060e6..33259ae36015106b149dee51f52725f672dd1185 100644 (file)
@@ -408,8 +408,9 @@ namespace __gnu_test
   void
   erase_external_iterators(std::multimap<int, int>& s);
 
-// NB: "must be compiled with C++11"
-#if __cplusplus >= 201103L
+#if __cplusplus < 201103L
+# error "must be compiled with C++11 (or later)"
+#else
 template<typename _Tp>
   void
   linkage_check_cxx98_cxx11_erase(_Tp& container)
index b0458dd33d36463e2bf9af2cb7dc28818dbc509f..eabff4c25c53e1ab415abd3528d702525968e3ce 100644 (file)
@@ -45,12 +45,14 @@ try_allocation()
 extern "C" void
 try_throw_exception()
 {
+#if __cpp_exceptions
   try
     {
       std::__throw_bad_exception();
     }
   catch (const std::exception& e)
     { }
+#endif
 }
 
 extern "C" void
@@ -75,8 +77,9 @@ try_function_random_fail()
   std::__throw_bad_exception();
 }
 
-#if __cplusplus < 201103L
-// "must be compiled with C++98"
+#if __cplusplus >= 201103L
+# error "must be compiled with C++98"
+#else
   void
   erase_external(std::set<int>& s)
   { s.erase(s.begin()); }