Fix GCC C++20 modules compilation #5103 (#5164)

* Fix: Add GCC diagnostic pragmas for C++ modules support (issue #5103)

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Fix: GCC C++20 modules with __cplusplus >= 202002L check (#5103)

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Fix: Remove indentation from nested preprocessor directives and disable astyle preprocessor indentation

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Update amalgamated files with correct preprocessor directive indentation

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

* Fix GCC build for issue #5103; refresh amalgamated header

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>

---------

Signed-off-by: hariomphulre <hariiomphullre@gmail.com>
This commit is contained in:
Hariom Phulre
2026-05-15 20:34:42 +05:30
committed by GitHub
parent 630beaeb05
commit bb5404bb86
3 changed files with 39 additions and 7 deletions
+9 -7
View File
@@ -8,6 +8,15 @@
module;
// GCC workaround for C++ modules support.
// When using C++20 modules, some compilers (particularly GCC) may have issues
// with template instantiations in the module preamble. If you encounter
// "redefinition" errors when including nlohmann/json.hpp, try one of:
// 1. Include nlohmann/json.hpp in your module preamble BEFORE other #includes
// 2. Or use: import nlohmann.json; instead of #include <nlohmann/json.hpp>
// 3. Or upgrade to a newer GCC version with better modules support.
// See: https://github.com/nlohmann/json/issues/5103
#include <nlohmann/json.hpp>
export module nlohmann.json;
@@ -41,10 +50,3 @@ namespace detail
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END
export namespace std
{
using std::hash;
using std::less;
using std::swap;
} // namespace std