From a64fc21243f4153d6030c9cc1ee475d426ec79b5 Mon Sep 17 00:00:00 2001 From: Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Fri, 8 May 2026 00:57:50 -0400 Subject: [PATCH] Fix missing exports from `json.cppm` (#5137) * Fix missing exports from `json.cppm` Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> * Update documentation to describe what symbols are exported Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> * Add mention of `std` symbols Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> * Add `json_literals` inline namespace to `using` statement Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> * Remove internals (`nlohmann::detail::*`) from module Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> * Omit internals (`nlohmann::detail::*`) from modules documentation Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> * Restore `nlohmann::detail` symbols with mention of the MSVC bug Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> --------- Signed-off-by: Miko <110693261+mikomikotaishi@users.noreply.github.com> --- docs/mkdocs/docs/features/modules.md | 14 ++++++- src/modules/json.cppm | 56 ++++++++++++++++++---------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/docs/mkdocs/docs/features/modules.md b/docs/mkdocs/docs/features/modules.md index 6068108b8..6574a9221 100644 --- a/docs/mkdocs/docs/features/modules.md +++ b/docs/mkdocs/docs/features/modules.md @@ -24,11 +24,21 @@ json data = json::parse(f); ``` ## Modules do not export macros -It should be noted that as modules do not export macros, the `nlohmann.json` module will not export any macros, but rather only the following symbols: +It should be noted that as modules do not export macros, the `nlohmann.json` module will not export any macros. +## Exported symbols +Only the following symbols are exported from `nlohmann.json`: - `nlohmann::adl_serializer` - `nlohmann::basic_json` - `nlohmann::json` - `nlohmann::json_pointer` -- `nlohmann::ordered_map` - `nlohmann::ordered_json` +- `nlohmann::ordered_map` +- `nlohmann::to_string` +- `nlohmann::literals::json_literals::operator""_json` +- `nlohmann::literals::json_literals::operator""_json_pointer` + +The following specialisations of `std` symbols are also exported: +- `std::hash` +- `std::less` +- `std::swap` diff --git a/src/modules/json.cppm b/src/modules/json.cppm index 623d8cb81..0930483af 100644 --- a/src/modules/json.cppm +++ b/src/modules/json.cppm @@ -1,32 +1,50 @@ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.12.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2026 Niels Lohmann +// SPDX-License-Identifier: MIT + module; #include export module nlohmann.json; -export namespace nlohmann { - using ::nlohmann::adl_serializer; - using ::nlohmann::basic_json; - using ::nlohmann::json; - using ::nlohmann::json_pointer; - using ::nlohmann::ordered_json; - using ::nlohmann::ordered_map; -} // namespace nlohmann - +export NLOHMANN_JSON_NAMESPACE_BEGIN +using NLOHMANN_JSON_NAMESPACE::adl_serializer; +using NLOHMANN_JSON_NAMESPACE::basic_json; +using NLOHMANN_JSON_NAMESPACE::json; +using NLOHMANN_JSON_NAMESPACE::json_pointer; +using NLOHMANN_JSON_NAMESPACE::ordered_json; +using NLOHMANN_JSON_NAMESPACE::ordered_map; +using NLOHMANN_JSON_NAMESPACE::to_string; + +inline namespace literals +{ +inline namespace json_literals +{ + using NLOHMANN_JSON_NAMESPACE::literals::json_literals::operator""_json; + using NLOHMANN_JSON_NAMESPACE::literals::json_literals::operator""_json_pointer; +} // namespace json_literals +} // namespace literals + +// Note: the following nlohmann::detail symbols must be exported due to +// an MSVC bug failing to compile without these symbols visible (ticket #3970) namespace detail { - export using NLOHMANN_JSON_NAMESPACE::detail::json_sax_dom_callback_parser; - export using NLOHMANN_JSON_NAMESPACE::detail::unknown_size; + using NLOHMANN_JSON_NAMESPACE::detail::json_sax_dom_callback_parser; + using NLOHMANN_JSON_NAMESPACE::detail::unknown_size; } // namespace detail -export using NLOHMANN_JSON_NAMESPACE::adl_serializer; -export using NLOHMANN_JSON_NAMESPACE::basic_json; -export using NLOHMANN_JSON_NAMESPACE::json; -export using NLOHMANN_JSON_NAMESPACE::json_pointer; -export using NLOHMANN_JSON_NAMESPACE::ordered_json; -export using NLOHMANN_JSON_NAMESPACE::ordered_map; -export using NLOHMANN_JSON_NAMESPACE::to_string; - NLOHMANN_JSON_NAMESPACE_END + +export namespace std +{ + using std::hash; + using std::less; + using std::swap; +} // namespace std