From 78bbe1532563c6746ad672487d69218e96818540 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 28 Nov 2020 14:17:59 +0000 Subject: [PATCH 01/10] Add a destructor assertion catch macro --- STL_Extension/include/CGAL/assertions.h | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 From 96024d1bb1bea1e98fc49808fa70c9f7cc3c8873 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 28 Nov 2020 14:25:25 +0000 Subject: [PATCH 02/10] Fix uncaught exception in K3_tree.h --- Nef_3/include/CGAL/Nef_3/K3_tree.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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: From 9d442f26c783a6e3416c3b5b2d56b0ec28ffe3d4 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 28 Nov 2020 17:48:05 +0000 Subject: [PATCH 03/10] Fix uncaught exception in VRML_2_ostream.h --- Stream_support/include/CGAL/IO/VRML/VRML_2_ostream.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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() From 35c148078ce711321d7c557319d8516a3028c8fc Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sat, 28 Nov 2020 20:26:00 +0000 Subject: [PATCH 04/10] Fix uncaught exception in Sphere_map.h --- Nef_S2/include/CGAL/Nef_S2/Sphere_map.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Nef_S2/include/CGAL/Nef_S2/Sphere_map.h b/Nef_S2/include/CGAL/Nef_S2/Sphere_map.h index 93670a125e2..0ee5d431292 100644 --- a/Nef_S2/include/CGAL/Nef_S2/Sphere_map.h +++ b/Nef_S2/include/CGAL/Nef_S2/Sphere_map.h @@ -229,7 +229,12 @@ public: Sphere_map(bool = false) : boundary_item_(boost::none), svertices_(), sedges_(), sfaces_(), shalfloop_() {} - ~Sphere_map() { clear(); } + ~Sphere_map() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) + { + CGAL_destructor_assertion_catch( + clear(); + ); + } Sphere_map(const Self& D) : boundary_item_(boost::none), svertices_(D.svertices_), From e222a423aff1070ae92d0e443bd3459b19620f9d Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 29 Nov 2020 11:30:21 +0000 Subject: [PATCH 05/10] Fix uncaught exception in Nef_polyhedron_S2.h --- Nef_S2/include/CGAL/Nef_polyhedron_S2.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Nef_S2/include/CGAL/Nef_polyhedron_S2.h b/Nef_S2/include/CGAL/Nef_polyhedron_S2.h index 10003b5b47a..59613249388 100644 --- a/Nef_S2/include/CGAL/Nef_polyhedron_S2.h +++ b/Nef_S2/include/CGAL/Nef_polyhedron_S2.h @@ -73,7 +73,12 @@ class Nef_polyhedron_S2_rep { public: Nef_polyhedron_S2_rep() : sm_() {} Nef_polyhedron_S2_rep(const Self&) : sm_() {} - ~Nef_polyhedron_S2_rep() { sm_.clear(); } + ~Nef_polyhedron_S2_rep() CGAL_NOEXCEPT(CGAL_NO_ASSERTIONS_BOOL) + { + CGAL_destructor_assertion_catch( + sm_.clear(); + ); + } }; /*{\Moptions print_title=yes }*/ From ce26378d5431dd1f89eb482fef246edd11ec1d6f Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 29 Nov 2020 12:11:37 +0000 Subject: [PATCH 06/10] Fix uncaught exception in SNC_point_locator.h --- Nef_3/include/CGAL/Nef_3/SNC_point_locator.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 3b81b1119c0..e381a9ae60a 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: "< Date: Sun, 29 Nov 2020 14:42:55 +0000 Subject: [PATCH 07/10] Fix uncaught exception in Handle_for.h --- STL_Extension/include/CGAL/Handle_for.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/STL_Extension/include/CGAL/Handle_for.h b/STL_Extension/include/CGAL/Handle_for.h index 537096b6e73..97543f58db8 100644 --- a/STL_Extension/include/CGAL/Handle_for.h +++ b/STL_Extension/include/CGAL/Handle_for.h @@ -149,12 +149,14 @@ public: return *this; } - ~Handle_for() + ~Handle_for() noexcept { - if (--(ptr_->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 From a7abec0a422a145fe73a18735bc3ceddfb3c244b Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 29 Nov 2020 15:21:49 +0000 Subject: [PATCH 08/10] Add noexcept to Ref_counted_base in Straight_skeleton_aux.h --- .../include/CGAL/Straight_skeleton_2/Straight_skeleton_aux.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From e7aebc424ec965a2e5231edfaf517d6c62e74831 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 29 Nov 2020 14:42:55 +0000 Subject: [PATCH 09/10] Fix uncaught exception in In_place_list.h --- STL_Extension/include/CGAL/In_place_list.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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); From 1373150f1da4ad94ac12890b682688a2dca6e1f4 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Sun, 29 Nov 2020 14:42:55 +0000 Subject: [PATCH 10/10] Fix uncaught exception in HalfedgeDS_list.h --- HalfedgeDS/include/CGAL/HalfedgeDS_list.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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),