From: Wolfgang Bangerth Date: Tue, 6 Aug 2024 17:17:18 +0000 (-0600) Subject: Make sure noexcept functions are indeed noexcept. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d0596bf44302078b3cf992dc3309b0ec87229b1;p=dealii.git Make sure noexcept functions are indeed noexcept. --- diff --git a/include/deal.II/base/smartpointer.h b/include/deal.II/base/smartpointer.h index 34c74b126d..73728ca047 100644 --- a/include/deal.II/base/smartpointer.h +++ b/include/deal.II/base/smartpointer.h @@ -335,7 +335,18 @@ inline SmartPointer::SmartPointer(SmartPointer &&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::operator=(SmartPointer &&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::operator=(SmartPointer &&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;