Skip to content

Adds support for C++20 modules - #535

Draft
anarthal wants to merge 17 commits into
boostorg:developfrom
anarthal:feature/cxx20-modules
Draft

anarthal wants to merge 17 commits into
boostorg:developfrom
anarthal:feature/cxx20-modules

Conversation

@anarthal

@anarthal anarthal commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Adds "compatibility headers" <boost/config/std/xyz.hpp> to easily ifdef-out std dependencies in other libraries
Adds boost/config/disable_module_warnings.hpp, to disable warnings about angle-bracket includes in purviews
Changes some includes under some compilers to be more lightweight

@anarthal

anarthal commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

See boostorg/cmake#105 for the full discussion, https://github.com/anarthal/boost-cmake/blob/feature/cxx20-modules/modules.md for the rationale I've been following.

@jzmaddock

Copy link
Copy Markdown
Collaborator

I'm not necessarily against this, but it will need documentation and testing support.

@soroshsabz

Copy link
Copy Markdown

soroshsabz added a commit to soroshsabz/program_options that referenced this pull request Oct 23, 2026
…ncludes

Every standard-header include of the module units (the interface and
the BOOST_PROGRAM_OPTIONS_MODULE_UNIT preludes in src/*.cpp) now goes
through a local compatibility shim in src/cppm/std/, following the
pattern of the boost/config/std headers from boostorg/config PR #535
(Adds support for C++20 modules, not merged yet):

    #ifdef BOOST_USE_MODULES
    #ifndef BOOST_IN_MODULE_PURVIEW
    import std;
    #endif
    #else
    #include <string>
    #endif

Today the shims compile to the plain includes (no behavior change);
once PR #535 is merged and the future modules mode (BOOST_USE_MODULES)
is used, they provide import std instead of textual includes inside
module units. Each shim carries a TODO comment to replace it with the
boost/config/std counterpart at that point; the README and the
documentation mention the PR as well.

Validated in fresh build directories: 15/15 tests, and the module test
with import std.
soroshsabz added a commit to soroshsabz/program_options that referenced this pull request Oct 23, 2026
…ST_USE_MODULES

Every standard-header inclusion in the library's headers and sources is
now wrapped in one compatibility guard per include block, following the
pattern of the boost/config/std headers from boostorg/config PR #535
(Adds support for C++20 modules, not merged yet):

    #ifdef BOOST_USE_MODULES
    #ifndef BOOST_IN_MODULE_PURVIEW
    import std;
    #endif
    #else
    #include <...>
    #endif

The guards are inactive today (BOOST_USE_MODULES is not defined), so
behavior is unchanged; each carries a TODO to switch to
<boost/config/std/...> when the PR is merged. In module units the
guarded std block sits after the textual dependency preloads, keeping
the MSVC-safe textual-before-import order, and the units define
BOOST_IN_MODULE_PURVIEW after their module declaration, per the
convention of that PR.

BOOST_USE_MODULES can now be enabled from CMake: the option activates
the module build, defines the macro for the module target, and requires
the toolchain std module (CMAKE_CXX_MODULE_STD plus a standard in
CMAKE_CXX_COMPILER_IMPORT_STD; fatal error otherwise). Full activation
of the ecosystem mode additionally requires modularized dependencies:
under this flag, already-converted dependencies such as Boost.TypeIndex
switch their headers to importing their own modules, superseding the
textual preloads used here until the PR #535 ecosystem lands. Noted in
CMakeLists.txt, README.md and doc/modules.xml.

Validated in fresh build directories: all 15 tests (classic build
unchanged) and the module test, both with textual preloads and with
import std.
soroshsabz added a commit to soroshsabz/program_options that referenced this pull request Oct 23, 2026
convert.cpp originally included the standard headers before the Boost
dependencies; the restructuring had moved them below. Restore the
original order: the standard-library guard now sits at the headers'
original position with the exact boostorg/config#535 pattern
(BOOST_USE_MODULES branch).

Because the textual Boost dependency includes follow it, the
BOOST_PROGRAM_OPTIONS_USE_STD_MODULE 'import std;' for this file moves
into the module closing block (after all textual includes, before the
module declaration): MSVC reconciles textual includes followed by an
explicit import, but rejects an import followed by textual includes.

Validated in fresh build directories: all 15 tests (classic build
unchanged), and the module test with textual preloads and with
import std.
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.

3 participants