Skip to content

Does not work in C++23 due to conflicts with import std cxx modules #2969

Open
@igormcoelho

Description

@igormcoelho

Describe the bug
In past discussions, Catch2 devs explained that it's not possible to migrate the project for CXX Modules, because modules cannot export macros, which is correct (#2299). However, even if the user has cxx modules in its code, specially C++23 import std, then it cannot currently interoperate with header only catch2, because it imposes its #include , generating ODR with import std, if compiler is not "smart enough" (which is currently the case and maybe will never be fully solved).
My problem now is that I'm a long time Catch2 user, and I cannot make it work with Clang 19 or GCC 15, because I'm using import std on C++23 and that's incompatible with current Catch2 design (but it's easy to solve!).

Expected behavior
Catch2 should provide some way to disable its #include for STD things, for example, adding an option or macro like "CATCH2_DISABLE_STD_INCLUDE"... so , all #include should be surrounded by this option:

#ifndef CATCH2_DISABLE_STD_INCLUDE
#include <string>
#include <vector>
#endif

Macro name can also be CATCH_USE_STDLIB_MODULE, as in, #2575, but I don't know if Catch2 is interested in really using import std... maybe not! But this proposal here is simpler, it just allows users to choose between its own import std or the current Catch2 #include dependencies.

Reproduction steps
Create some Module.cpp file, with import std, and try to #include catch2, or try to link against it. ODR violations will be reported.

Platform information:

  • OS: Ubuntu Linux
  • Compiler: Clang 19 or GCC 15

Additional context
If necessary, I can do the PR... specially, for the amalgamated hpp file, it would be nice to disable all its header inclusions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions