diff --git a/HalfedgeDS/include/CGAL/HalfedgeDS_list.h b/HalfedgeDS/include/CGAL/HalfedgeDS_list.h index aecf7b7e29b..664be1c2c30 100644 --- a/HalfedgeDS/include/CGAL/HalfedgeDS_list.h +++ b/HalfedgeDS/include/CGAL/HalfedgeDS_list.h @@ -395,7 +395,11 @@ public: // halfedges, and f faces. The reservation sizes are a hint for // optimizing storage allocation. They are not used here. - ~HalfedgeDS_list() { clear(); } + ~HalfedgeDS_list() noexcept { + try { + clear(); + } catch (...) {} + } HalfedgeDS_list( const Self& hds) : vertices( hds.vertices), diff --git a/Nef_3/include/CGAL/Nef_3/K3_tree.h b/Nef_3/include/CGAL/Nef_3/K3_tree.h index c3b8aaecffc..b551b5c1625 100644 --- a/Nef_3/include/CGAL/Nef_3/K3_tree.h +++ b/Nef_3/include/CGAL/Nef_3/K3_tree.h @@ -442,12 +442,15 @@ friend std::ostream& operator<< } -~Node() { +~Node() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) +{ CGAL_NEF_TRACEN("~Node: deleting node..."); - if( !is_leaf()) { - delete left_node; - delete right_node; - } + CGAL_destructor_assertion_catch( + if( !is_leaf()) { + delete left_node; + delete right_node; + } + ); } private: @@ -1103,9 +1106,12 @@ bool update( Node* node, return (left_updated || right_updated); } -~K3_tree() { +~K3_tree() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) +{ CGAL_NEF_TRACEN("~K3_tree: deleting root..."); - delete root; + CGAL_destructor_assertion_catch( + delete root; + ); } private: diff --git a/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h b/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h index bc3af7976af..46a6dae4962 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h @@ -126,7 +126,8 @@ public: virtual void add_vertex(Vertex_handle) {} - virtual ~SNC_point_locator() { + virtual ~SNC_point_locator() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) + { CGAL_NEF_CLOG(""); CGAL_NEF_CLOG("construction_time: "<count) == 0) { - Allocator_traits::destroy(allocator, ptr_); - allocator.deallocate( ptr_, 1); - } + try{ + if (--(ptr_->count) == 0) { + Allocator_traits::destroy(allocator, ptr_); + allocator.deallocate( ptr_, 1); + } + } catch(...) {} } void diff --git a/STL_Extension/include/CGAL/In_place_list.h b/STL_Extension/include/CGAL/In_place_list.h index 89fd3da3c82..e19c8ca5e4d 100644 --- a/STL_Extension/include/CGAL/In_place_list.h +++ b/STL_Extension/include/CGAL/In_place_list.h @@ -445,9 +445,11 @@ public: (*node).prev_link = node; insert(begin(), x.begin(), x.end()); } - ~In_place_list() { - erase(begin(), end()); - put_node(node); + ~In_place_list() noexcept { + try { + erase(begin(), end()); + put_node(node); + } catch(...) {} } Self& operator=(const Self& x); diff --git a/STL_Extension/include/CGAL/assertions.h b/STL_Extension/include/CGAL/assertions.h index caa0237fc7d..e13f181f970 100644 --- a/STL_Extension/include/CGAL/assertions.h +++ b/STL_Extension/include/CGAL/assertions.h @@ -79,6 +79,7 @@ inline bool possibly(Uncertain c); #if defined(CGAL_NO_ASSERTIONS) # define CGAL_assertion(EX) (static_cast(0)) # define CGAL_destructor_assertion(EX) (static_cast(0)) +# define CGAL_destructor_assertion_catch(CODE) CODE # define CGAL_assertion_msg(EX,MSG) (static_cast(0)) # define CGAL_assertion_code(CODE) # ifdef CGAL_ASSUME @@ -94,9 +95,11 @@ inline bool possibly(Uncertain c); # if __cpp_lib_uncaught_exceptions || ( _MSVC_LANG >= 201703L ) // C++17 # define CGAL_destructor_assertion(EX) \ (CGAL::possibly(EX)||(std::uncaught_exceptions() > 0)?(static_cast(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__)) +# define CGAL_destructor_assertion_catch(CODE) try{ CODE } catch(...) { if(std::uncaught_exceptions() <= 0) throw; } # else // use C++03 `std::uncaught_exception()` # define CGAL_destructor_assertion(EX) \ (CGAL::possibly(EX)||std::uncaught_exception()?(static_cast(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__)) +# define CGAL_destructor_assertion_catch(CODE) try{ CODE } catch(...) { if(!std::uncaught_exception()) throw; } # endif // use C++03 `std::uncaught_exception()` # define CGAL_assertion_msg(EX,MSG) \ (CGAL::possibly(EX)?(static_cast(0)): ::CGAL::assertion_fail( # EX , __FILE__, __LINE__, MSG)) @@ -293,11 +296,19 @@ inline bool possibly(Uncertain c); #if defined(CGAL_NO_WARNINGS) # define CGAL_warning(EX) (static_cast(0)) +# define CGAL_destructor_warning(EX) (static_cast(0)) # define CGAL_warning_msg(EX,MSG) (static_cast(0)) # define CGAL_warning_code(CODE) #else # define CGAL_warning(EX) \ (CGAL::possibly(EX)?(static_cast(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__)) +# if __cpp_lib_uncaught_exceptions || ( _MSVC_LANG >= 201703L ) // C++17 +# define CGAL_destructor_warning(EX) \ + (CGAL::possibly(EX)||(std::uncaught_exceptions() > 0)?(static_cast(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__)) +# else // use C++03 `std::uncaught_exception()` +# define CGAL_destructor_warning(EX) \ + (CGAL::possibly(EX)||std::uncaught_exception()?(static_cast(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__)) +# endif // use C++03 `std::uncaught_exception()` # define CGAL_warning_msg(EX,MSG) \ (CGAL::possibly(EX)?(static_cast(0)): ::CGAL::warning_fail( # EX , __FILE__, __LINE__, MSG)) # define CGAL_warning_code(CODE) CODE diff --git a/Straight_skeleton_2/include/CGAL/Straight_skeleton_2/Straight_skeleton_aux.h b/Straight_skeleton_2/include/CGAL/Straight_skeleton_2/Straight_skeleton_aux.h index 532d72e3a88..7e642e8b10b 100644 --- a/Straight_skeleton_2/include/CGAL/Straight_skeleton_2/Straight_skeleton_aux.h +++ b/Straight_skeleton_2/include/CGAL/Straight_skeleton_2/Straight_skeleton_aux.h @@ -164,7 +164,7 @@ private: Ref_counted_base& operator=( Ref_counted_base const &); protected: Ref_counted_base(): mCount(0) {} - virtual ~Ref_counted_base() {} + virtual ~Ref_counted_base() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) {} public: void AddRef() const { ++mCount; } void Release() const diff --git a/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h index 08e8fdd7e49..d200643068d 100644 --- a/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h +++ b/Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h @@ -30,7 +30,12 @@ class VRML_2_ostream public: VRML_2_ostream() : m_os(nullptr) {} VRML_2_ostream(std::ostream& o) : m_os(&o) { header(); } - ~VRML_2_ostream() { close(); } + ~VRML_2_ostream() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) + { + CGAL_destructor_assertion_catch( + close(); + ); + } void open(std::ostream& o) { m_os = &o; header(); } void close()