Skip to content

example: register the shared classes in both modules, as Windows requires - #114

Merged
jll63 merged 1 commit into
boostorg:developfrom
jll63:fix/windows-cross-module-classes
Sep 16, 2026
Merged

jll63 merged 1 commit into
boostorg:developfrom
jll63:fix/windows-cross-module-classes

Conversation

@jll63

@jll63 jll63 commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

(Written by Claude Code, on behalf of @jll63.)

The implicit_linking example aborts on Windows, and always has:

unknown class struct Wolf

extensions.cpp — the DLL — registers Animal, Herbivore, Cow,
Carnivore and Wolf. main.cpp creates a Wolf with new and dispatches on
it. Windows keeps one type_info object per module, so the program's Wolf and
the library's Wolf are two different type ids, and only the library's was ever
registered. ELF and Mach-O merge the two, which is why it passes everywhere
else.

This is the case cpp:use_classes[] already documents:

If a class is identified by different type ids in different translation units,
it must be registered in as many translation units as necessary … The only
such case known to the author is when using Windows DLLs.

The example was the one place that did not follow its own rule. The program now
registers the library's classes as well — redundant and harmless on ELF, and
what makes the example work on Windows. shared_libraries.adoc says why, next
to the example, since the extra line would otherwise look like an oversight.

Not a regression

Measured with MSVC v18 BuildTools, Ninja, Release, against three trees:

tree result
7eb56f5 — "support DSO/DLL on all platforms (#75)", the commit that added the example fails
develop fails
this branch passes

There is no good commit to bisect to; it has never worked on Windows.

Why CI never caught it

The doc examples are built only when this project is configured as the root
with BOOST_OPENMETHOD_BUILD_TESTS=ON, which no CI job does: the Boost.CI jobs
build the library inside the super-project, where that option defaults to OFF,
and b2's test/Jamfile globs test_*.cpp and compile_fail_*.cpp only. So
boost_openmethod-static runs in a local root CMake build and nowhere else, on
any platform.

Worth considering separately — not in this PR — whether one CI job should
configure the project as root with examples on, or this class of breakage stays
invisible.

Tests

186/186 under gcc 13.3 Release with warnings as errors; the affected test
verified directly under MSVC as above. The existing
test/implicit_shared_libraries tests are unaffected — they already register
their classes in both modules, which is why they pass on Windows today.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RQG6CbE4o2agseE7bDVzHS

…ires

The implicit_linking example has never run on Windows. Its library registers
Animal, Herbivore, Cow, Carnivore and Wolf; the program creates a Wolf with
`new` and dispatches on it, and MSVC aborts:

    unknown class struct Wolf

Windows keeps one `type_info` object per module, so the program's `Wolf` and
the library's `Wolf` are two different type ids, and only the library's was
ever registered. ELF and Mach-O merge the two, which is why it passes
everywhere else. `use_classes` already documents the rule - "a class must be
registered in as many translation units as necessary ... The only such case
known to the author is when using Windows DLLs" - and the example was the one
place that did not follow it.

The program now registers the library's classes as well. On ELF that is
redundant and harmless; on Windows it is what makes the example work. The page
says why, next to the example.

Verified with MSVC v18 (Ninja, Release): the test fails on develop and at
7eb56f5, the commit that introduced the example, and passes with this change.
Nothing in CI caught it because the doc examples are built only when this
project is configured as the root with tests enabled, which no CI job does -
the Boost.CI jobs build it inside the super-project, and b2's test/Jamfile
globs test_*.cpp and compile_fail_*.cpp only.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RQG6CbE4o2agseE7bDVzHS
@cppalliance-bot

Copy link
Copy Markdown

An automated preview of the documentation is available at https://114.openmethod.prtest3.cppalliance.org/libs/openmethod/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-09-16 00:57:04 UTC

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.25%. Comparing base (d44aa59) to head (f4fc118).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #114      +/-   ##
===========================================
- Coverage    93.51%   93.25%   -0.26%     
===========================================
  Files           22       22              
  Lines         1695     1706      +11     
  Branches       504      509       +5     
===========================================
+ Hits          1585     1591       +6     
- Misses          66       71       +5     
  Partials        44       44              

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 261ebed...f4fc118. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jll63
jll63 merged commit eaac23e into boostorg:develop Sep 16, 2026
54 of 56 checks passed
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.

2 participants