diff options
| author | Leitwolf11 | 2026-11-01 19:11:27 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-11-01 19:11:27 +0300 |
| commit | 2aea9dafd283d69bec459ea0d495c25d1f6a0f94 (patch) | |
| tree | e478374100157fe4d0aef16e582dbcabda51e2c1 /src | |
| parent | c51d15273e87267215e5877edc268e7db354187b (diff) | |
| download | catch3-2aea9dafd283d69bec459ea0d495c25d1f6a0f94.tar.gz | |
Keep the mock lock alive to the end of the process
A static mutex needs an exit-time destructor, which Clang's warnings
refuse, and a mock of static lifetime can outlive it. The test seam is
held the same way, and a test covers a mock method with nothing after
its parameters, which needs an empty variadic argument to stay valid
under -Wpedantic.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Progmasoft/Catch3/Mock.hpp | 7 | ||||
| -rw-r--r-- | src/Progmasoft/Mock.cpp | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/Progmasoft/Catch3/Mock.hpp b/src/Progmasoft/Catch3/Mock.hpp index 1e077ac8..f100041c 100644 --- a/src/Progmasoft/Catch3/Mock.hpp +++ b/src/Progmasoft/Catch3/Mock.hpp @@ -373,8 +373,8 @@ namespace Progmasoft::Catch3 } else if constexpr (std::is_copy_constructible_v<Result>) { - return Does([held = Result(std::forward<Value>(value))]( - Arguments...) -> Result { + return Does([held = static_cast<Result>(std::forward<Value>( + value))](Arguments...) -> Result { return held; }); } @@ -925,7 +925,8 @@ namespace Progmasoft::Catch3 field, \ arguments, \ CATCH3_INTERNAL_MOCK_EXPAND(CATCH3_INTERNAL_MOCK_COUNT arguments), \ - CATCH3_INTERNAL_MOCK_EXPAND(CATCH3_INTERNAL_MOCK_FIRST(__VA_ARGS__)))) + CATCH3_INTERNAL_MOCK_EXPAND( \ + CATCH3_INTERNAL_MOCK_FIRST(__VA_ARGS__, )))) /// Declares the member `name` of a mock class and, beside it, the mock /// `name##Mock` that `CATCH3_EXPECT_CALL` takes. The parenthesized list of diff --git a/src/Progmasoft/Mock.cpp b/src/Progmasoft/Mock.cpp index 2897838c..b1364450 100644 --- a/src/Progmasoft/Mock.cpp +++ b/src/Progmasoft/Mock.cpp @@ -93,8 +93,9 @@ namespace Progmasoft::Catch3::Detail std::unique_lock<std::recursive_mutex> LockMocks() { - static std::recursive_mutex mutex; - return std::unique_lock<std::recursive_mutex>{ mutex }; + // Never destroyed: a mock of static lifetime can go after it would. + static auto *mutex = new std::recursive_mutex; + return std::unique_lock<std::recursive_mutex>{ *mutex }; } void |