From b633bb5b84278e59ad07b7bc9b51110e21613aec Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 10 Jun 2021 10:39:04 -0700 Subject: [PATCH] Inserting `#ifdef` to preempt Windows fatal exception. --- tests/test_class_sh_shared_from_this.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_class_sh_shared_from_this.cpp b/tests/test_class_sh_shared_from_this.cpp index 852d58679..d7673f0c7 100644 --- a/tests/test_class_sh_shared_from_this.cpp +++ b/tests/test_class_sh_shared_from_this.cpp @@ -75,6 +75,11 @@ void obj_sft_reset() { if (obj_sft == nullptr) throw std::runtime_error("Unexpected `use_count`s."); (*obj_sft).reset(); +#if defined(_MSC_VER) && _MSC_VER < 1912 + std::cout << "Preempting \"Windows fatal exception: access violation\": " + "(*obj_ign)->shared_from_this()" + << std::endl; +#else bool got_bad_weak_ptr = false; try { static_cast((*obj_ign)->shared_from_this()); @@ -85,6 +90,7 @@ void obj_sft_reset() { std::shared_ptr obj3(obj2.get(), labeled_delete("SkipDelete")); // Working again based on the shared_ptr that was created after obj_sft was reset: static_cast((*obj_ign)->shared_from_this()); +#endif } } // namespace shared_from_this_custom_deleters