[fix] error: module file CMakeFiles/__cmake_cxx23.dir/std.pcm cannot be loaded due to a configuration mismatch with the current compilation #4279 #4582
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[fix] error: module file CMakeFiles/__cmake_cxx23.dir/std.pcm cannot be loaded due to a configuration mismatch with the current compilation #4279
What I changed
Edited CMakeLists.txt in the add_module_library logic:
Compute a std_flag that honors CMAKE_CXX_EXTENSIONS:
If CMAKE_CXX_EXTENSIONS is ON, use -std=gnu++.
Otherwise use -std=c++.
Use ${std_flag} when invoking the compiler to precompile modules:
The precompile command previously used -std=c++ unconditionally; now it uses ${std_flag}.
Use ${std_flag} (and the same include dirs) when compiling the .o from the .pcm to ensure a consistent compile configuration.
Why this helps
The "configuration mismatch" (PCM/PCH load failure) is typically caused by the PCM being produced with a different -std variant (e.g., -std=gnu++23) than the compile unit loading it (e.g., -std=c++23). On Clang the difference between gnu++ and c++ influences whether GNU extensions are enabled; that triggers the "GNU extensions was enabled in PCH file but is currently disabled" diagnostic.
Making the precompile and compile use the same -std avoids that mismatch.
The errors showing that types from std (enable_if, conditional, etc.) are missing are consistent with the compiler being in a different configuration or precompiled header context (modules/PCH broken), so fixing the PCM config mismatch should eliminate those follow-on errors.