Repository navigation
Conversation
cfg<> is a variable template, so its initialization is unordered with respect to the suites defined at namespace scope. With clang-cl the runner is constructed after the suites of the same translation unit: they are added to a runner whose constructor has not been called yet and are discarded when it is. The program then runs no tests and exits with 0, e.g. example/run.cpp and example/suite.cpp, and test/ft runs one of its three suites. A runner with static storage duration is zero-initialized before any constructor is called, so a flag which every constructor sets tells the two cases apart. A suite registered too early is put aside and is adopted by the constructor. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
cfg<> is a variable template, so its initialization is unordered with respect to suites defined at namespace scope. clang-cl (19.1.5, MSVC 14.44 STL) constructs the runner after the suites of the same translation unit. The suites are added to a runner whose constructor has not been called yet and are discarded when it is.
The program then prints UT starts / Completed, runs no tests and exits with 0. On current master with -T ClangCl:
example/run.cpp and example/suite.cpp run no tests
test/ft runs one of its three suites (3 asserts instead of 6) and passes
MSVC, and Clang on macOS, happen to construct the runner first.
Solution
A runner with static storage duration is zero-initialized before any constructor is called, so a flag which every constructor sets tells the two cases apart. A suite registered too early is put aside and adopted by the constructor. suites_ stays a protected member, so derived runners are not affected.
This does not make the early call well-defined by the standard; it makes the existing pattern work regardless of the initialization order. Possibly related to #637.
I tried to find better solution but it looks like nothing else works well without architecture changes.
Testing
New unit test: registers a suite with zero-initialized storage, constructs the runner in it, and expects both the early and the late suite to run. It fails without the change.
ClangCl and v143 on Windows: full build and CTest pass; the examples above and test/ft now run all their tests under ClangCl.
Clang 23 on macOS with ASan/UBSan: CTest and all examples pass.