Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Make the start lock a never-destroyed object

A function-local static std::mutex has an exit-time destructor, which
the macOS build rejects with -Wexit-time-destructors. The lock is now
allocated once and never destroyed, which also keeps it usable by a
thread that starts a child while the process exits.
Commit
5ad02bccfcb925df02d1273901b6e248d477c5fa
Author
Leitwolf11 ·
Parents
826735e00bfa

Files · Download .tar.gz

Changes

 extras/catch_amalgamated.cpp      | 6 ++++--
 src/Progmasoft/Runner/Process.cpp | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/extras/catch_amalgamated.cpp b/extras/catch_amalgamated.cpp
index 7a1c9541..4b928849 100644
--- a/extras/catch_amalgamated.cpp
+++ b/extras/catch_amalgamated.cpp
@@ -16292,8 +16292,10 @@ namespace Progmasoft::Catch3::Runner
         std::mutex &
         StartLock()
         {
-            static std::mutex lock;
-            return lock;
+            // Never destroyed, so no exit-time destructor runs while a
+            // detached thread may still start a child.
+            static std::mutex *const lock = new std::mutex;
+            return *lock;
         }
     } // namespace
 
diff --git a/src/Progmasoft/Runner/Process.cpp b/src/Progmasoft/Runner/Process.cpp
index 41fa87f1..e3b0997b 100644
--- a/src/Progmasoft/Runner/Process.cpp
+++ b/src/Progmasoft/Runner/Process.cpp
@@ -621,8 +621,10 @@ namespace Progmasoft::Catch3::Runner
         std::mutex &
         StartLock()
         {
-            static std::mutex lock;
-            return lock;
+            // Never destroyed, so no exit-time destructor runs while a
+            // detached thread may still start a child.
+            static std::mutex *const lock = new std::mutex;
+            return *lock;
         }
     } // namespace