Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests/ToStringOptional.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-12-26 15:31:20 +0100
committerMartin Hořeňovský2025-12-26 15:53:30 +0100
commiteb3811c555eccd2de8b63ba16e0f62c444970acf (patch)
treefc288c56f87bb1972854dd54288b04bf22923f86 /tests/SelfTest/UsageTests/ToStringOptional.tests.cpp
parent343cc059fed6933849dab28fdd28969ee625fe47 (diff)
downloadcatch3-eb3811c555eccd2de8b63ba16e0f62c444970acf.tar.gz
Fix lifetime issues when using UNSCOPED_X message macros
The original implementation of `UNSCOPED_X` message macros used a clever hack to make the original implementation simpler: construct an instance of `ScopedMessage` to manage its lifetime, but store it in a vector, so its lifetime is not actually scope-based, and we can manage it through the vector instance. This hack made it so that the lifetime of the vector that manages the fake `ScopedMessage`s must be outlived by the vector with the actual messages. Originally this wasn't a problem, because they both lived inside the run context instance. However, since then these vectors became globals and thread-local. When this happened, it still wasn't a problem; the two globals were declared in the right order, so they were destroyed in the right order as well. Then, in f80956a43a3e276686ed59531b41617282d75a0c, these globals were turned into magic static globals to improve their behaviour in MSVC's Debug build mode. This caused their lifetimes to be runtime-dependent; if a specific test thread added its first scoped message before it added first unscoped message, the lifetimes would be correct. If it instead added first unscoped message before adding first scoped message, then there **might** be invalid reads during thread destruction. The fix is simple: do things properly and manage the lifetime of messages in `UNSCOPED_X` explicitly. Then we don't have to deal with the destruction of fake `ScopedMessage`s while the thread is being destroyed, and the lifetime of the two vectors is no longer tied together. I also threw them both into a new type, to encapsulate some of the unscoped message logic.
Diffstat (limited to 'tests/SelfTest/UsageTests/ToStringOptional.tests.cpp')
0 files changed, 0 insertions, 0 deletions