Skip to content

Keep suites registered before the runner is constructed - #722

Open
thed636 wants to merge 1 commit into
boost-ext:masterfrom
thed636:fix-suite-registration-order
Open

thed636 wants to merge 1 commit into
boost-ext:masterfrom
thed636:fix-suite-registration-order

Conversation

@thed636

@thed636 thed636 commented Nov 18, 2026 •

Copy link
Copy Markdown

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.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant