catchorg / catchorg/Catch2

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

Open
#2,969 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**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 (https://github.com/catchorg/Catch2/issues/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
#include
#endif
```

Macro name can also be `CATCH_USE_STDLIB_MODULE`, as in, https://github.com/catchorg/Catch2/issues/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.