]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make sure noexcept functions are indeed noexcept.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 6 Aug 2024 17:17:18 +0000 (11:17 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 10 Aug 2024 03:57:41 +0000 (21:57 -0600)
include/deal.II/base/smartpointer.h

index 34c74b126db7eb75fdd6b59db1030c6ab0a932ba..73728ca04741159cdf4948737f40ae7548f01e4f 100644 (file)
@@ -335,7 +335,18 @@ inline SmartPointer<T, P>::SmartPointer(SmartPointer<T, P> &&tt) noexcept
              ExcMessage("You can't move a smart pointer object that "
                         "is pointing to an object that is no longer alive."));
 
-      t->subscribe(&pointed_to_object_is_alive, id);
+      try
+        {
+          t->subscribe(&pointed_to_object_is_alive, id);
+        }
+      catch (...)
+        {
+          Assert(false,
+                 ExcMessage(
+                   "Calling subscribe() failed with an exception, but we "
+                   "are in a function that cannot throw exceptions. "
+                   "Aborting the program here."));
+        }
 
       // Release the rhs object as if we had moved all members away from
       // it directly:
@@ -452,7 +463,7 @@ SmartPointer<T, P>::operator=(SmartPointer<T, P> &&tt) noexcept
   else if (&tt != this)
     {
       // Let us unsubscribe from the current object
-      if (pointed_to_object_is_alive)
+      if (t != nullptr && pointed_to_object_is_alive)
         t->unsubscribe(&pointed_to_object_is_alive, id);
 
       // Then reset to the new object, and subscribe to it:
@@ -460,7 +471,18 @@ SmartPointer<T, P>::operator=(SmartPointer<T, P> &&tt) noexcept
              ExcMessage("You can't move a smart pointer object that "
                         "is pointing to an object that is no longer alive."));
       t = tt.get();
-      t->subscribe(&pointed_to_object_is_alive, id);
+      try
+        {
+          t->subscribe(&pointed_to_object_is_alive, id);
+        }
+      catch (...)
+        {
+          Assert(false,
+                 ExcMessage(
+                   "Calling subscribe() failed with an exception, but we "
+                   "are in a function that cannot throw exceptions. "
+                   "Aborting the program here."));
+        }
 
       // Finally release the rhs object since we moved its contents
       tt = nullptr;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.