From 97737f29bee6c218f6bd135879ca7ce8110fbc97 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 22 Oct 2025 11:34:53 +0200 Subject: [PATCH 1/5] :recycle: address CWG issue 2521 #4956 Signed-off-by: Niels Lohmann --- include/nlohmann/json.hpp | 21 ++++----------------- single_include/nlohmann/json.hpp | 21 ++++----------------- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 8979c2d1f4..0ef7b43912 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5273,11 +5273,7 @@ inline namespace json_literals /// @brief user-defined string literal for JSON values /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json operator ""_json(const char* s, std::size_t n) -#else - inline nlohmann::json operator "" _json(const char* s, std::size_t n) -#endif +inline nlohmann::json operator""_json(const char* s, std::size_t n) { return nlohmann::json::parse(s, s + n); } @@ -5285,11 +5281,7 @@ JSON_HEDLEY_NON_NULL(1) /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n) -#else - inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) -#endif +inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) { return nlohmann::json::json_pointer(std::string(s, n)); } @@ -5353,13 +5345,8 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC } // namespace std #if JSON_USE_GLOBAL_UDLS - #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - using nlohmann::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) - #else - using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) - #endif + using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) + using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) #endif #include diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index aafeaf5ae5..b73783a808 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -25376,11 +25376,7 @@ inline namespace json_literals /// @brief user-defined string literal for JSON values /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json operator ""_json(const char* s, std::size_t n) -#else - inline nlohmann::json operator "" _json(const char* s, std::size_t n) -#endif +inline nlohmann::json operator""_json(const char* s, std::size_t n) { return nlohmann::json::parse(s, s + n); } @@ -25388,11 +25384,7 @@ JSON_HEDLEY_NON_NULL(1) /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) -#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - inline nlohmann::json::json_pointer operator ""_json_pointer(const char* s, std::size_t n) -#else - inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) -#endif +inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) { return nlohmann::json::json_pointer(std::string(s, n)); } @@ -25456,13 +25448,8 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC } // namespace std #if JSON_USE_GLOBAL_UDLS - #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) - using nlohmann::literals::json_literals::operator ""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator ""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) - #else - using nlohmann::literals::json_literals::operator "" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator "" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) - #endif + using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) + using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) #endif // #include From 1ab4f7c1ee6cb3a184251555302903afcffb0d8d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 22 Oct 2025 12:35:46 +0200 Subject: [PATCH 2/5] :sparkles: add char8_t* overload for _json and _json_pointer #4956 Signed-off-by: Niels Lohmann --- docs/mkdocs/docs/api/operator_literal_json.md | 2 ++ .../docs/api/operator_literal_json_pointer.md | 2 ++ include/nlohmann/json.hpp | 16 ++++++++++++++++ single_include/nlohmann/json.hpp | 16 ++++++++++++++++ tests/src/unit-deserialization.cpp | 17 +++++++++++++++++ tests/src/unit-json_pointer.cpp | 14 ++++++++++++++ 6 files changed, 67 insertions(+) diff --git a/docs/mkdocs/docs/api/operator_literal_json.md b/docs/mkdocs/docs/api/operator_literal_json.md index a3a4bd28b5..fdf6e83695 100644 --- a/docs/mkdocs/docs/api/operator_literal_json.md +++ b/docs/mkdocs/docs/api/operator_literal_json.md @@ -2,6 +2,7 @@ ```cpp json operator ""_json(const char* s, std::size_t n); +json operator ""_json(const char8_t* s, std::size_t n); // since C++20 ``` This operator implements a user-defined string literal for JSON objects. It can be used by adding `#!cpp _json` to a @@ -59,3 +60,4 @@ Linear. - Added in version 1.0.0. - Moved to namespace `nlohmann::literals::json_literals` in 3.11.0. +- Added `char8_t*` overload in 3.12.1. diff --git a/docs/mkdocs/docs/api/operator_literal_json_pointer.md b/docs/mkdocs/docs/api/operator_literal_json_pointer.md index 423678c77b..2c3d6a13a8 100644 --- a/docs/mkdocs/docs/api/operator_literal_json_pointer.md +++ b/docs/mkdocs/docs/api/operator_literal_json_pointer.md @@ -2,6 +2,7 @@ ```cpp json_pointer operator ""_json_pointer(const char* s, std::size_t n); +json_pointer operator ""_json_pointer(const char8_t* s, std::size_t n); // since C++20 ``` This operator implements a user-defined string literal for JSON Pointers. It can be used by adding `#!cpp _json_pointer` @@ -62,3 +63,4 @@ Linear. - Added in version 2.0.0. - Moved to namespace `nlohmann::literals::json_literals` in 3.11.0. +- Added `char8_t*` overload in 3.12.1. diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0ef7b43912..284d71c79f 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5278,6 +5278,15 @@ inline nlohmann::json operator""_json(const char* s, std::size_t n) return nlohmann::json::parse(s, s + n); } +#if defined(__cpp_char8_t) +JSON_HEDLEY_NON_NULL(1) +inline nlohmann::json operator""_json(const char8_t* s, std::size_t n) +{ + return nlohmann::json::parse(reinterpret_cast(s), + reinterpret_cast(s) + n); +} +#endif + /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) @@ -5286,6 +5295,13 @@ inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std:: return nlohmann::json::json_pointer(std::string(s, n)); } +#if defined(__cpp_char8_t) +inline nlohmann::json::json_pointer operator""_json_pointer(const char8_t* s, std::size_t n) +{ + return nlohmann::json::json_pointer(std::string(reinterpret_cast(s), n)); +} +#endif + } // namespace json_literals } // namespace literals NLOHMANN_JSON_NAMESPACE_END diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b73783a808..32faa4c5e3 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -25381,6 +25381,15 @@ inline nlohmann::json operator""_json(const char* s, std::size_t n) return nlohmann::json::parse(s, s + n); } +#if defined(__cpp_char8_t) +JSON_HEDLEY_NON_NULL(1) +inline nlohmann::json operator""_json(const char8_t* s, std::size_t n) +{ + return nlohmann::json::parse(reinterpret_cast(s), + reinterpret_cast(s) + n); +} +#endif + /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) @@ -25389,6 +25398,13 @@ inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std:: return nlohmann::json::json_pointer(std::string(s, n)); } +#if defined(__cpp_char8_t) +inline nlohmann::json::json_pointer operator""_json_pointer(const char8_t* s, std::size_t n) +{ + return nlohmann::json::json_pointer(std::string(reinterpret_cast(s), n)); +} +#endif + } // namespace json_literals } // namespace literals NLOHMANN_JSON_NAMESPACE_END diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 58fe958ea2..0c16afbd78 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -1132,6 +1132,23 @@ TEST_CASE("deserialization") CHECK(object_count == 4); } } + + // build with C++20 + // JSON_HAS_CPP_20 +#if defined(__cpp_char8_t) + SECTION("Using _json with char8_t literals #4945") + { + // Regular narrow string literal + auto j1 = R"({"key": "value", "num": 42})"_json; + CHECK(j1["key"] == "value"); + CHECK(j1["num"] == 42); + + // UTF-8 prefixed literal (C++20 and later) + auto j2 = u8R"({"emoji": "😀", "msg": "hello"})"_json; + CHECK(j2["emoji"] == "😀"); + CHECK(j2["msg"] == "hello"); + } +#endif } // select the types to test - char8_t is only available since C++20 if and only diff --git a/tests/src/unit-json_pointer.cpp b/tests/src/unit-json_pointer.cpp index 149eff00a2..b36331eba3 100644 --- a/tests/src/unit-json_pointer.cpp +++ b/tests/src/unit-json_pointer.cpp @@ -788,4 +788,18 @@ TEST_CASE("JSON pointers") CHECK_FALSE(ptr_oj != ptr); } } + + // build with C++20 + // JSON_HAS_CPP_20 +#if defined(__cpp_char8_t) + SECTION("Using _json_pointer with char8_t literals #4945") + { + const json j = R"({"a": {"b": {"c": 123}}})"_json; + const auto p1 = "/a/b/c"_json_pointer; + CHECK(j[p1] == 123); + + const auto p2 = u8"/a/b/c"_json_pointer; + CHECK(j[p2] == 123); + } +#endif } From 2adf75da66ee330090dfee5a792b18960c17433d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 22 Oct 2025 16:30:08 +0200 Subject: [PATCH 3/5] :rewind: revert changes for #4945 Signed-off-by: Niels Lohmann --- docs/mkdocs/docs/api/operator_literal_json.md | 2 -- .../docs/api/operator_literal_json_pointer.md | 2 -- include/nlohmann/json.hpp | 16 ---------------- single_include/nlohmann/json.hpp | 16 ---------------- tests/src/unit-deserialization.cpp | 17 ----------------- tests/src/unit-json_pointer.cpp | 14 -------------- 6 files changed, 67 deletions(-) diff --git a/docs/mkdocs/docs/api/operator_literal_json.md b/docs/mkdocs/docs/api/operator_literal_json.md index fdf6e83695..a3a4bd28b5 100644 --- a/docs/mkdocs/docs/api/operator_literal_json.md +++ b/docs/mkdocs/docs/api/operator_literal_json.md @@ -2,7 +2,6 @@ ```cpp json operator ""_json(const char* s, std::size_t n); -json operator ""_json(const char8_t* s, std::size_t n); // since C++20 ``` This operator implements a user-defined string literal for JSON objects. It can be used by adding `#!cpp _json` to a @@ -60,4 +59,3 @@ Linear. - Added in version 1.0.0. - Moved to namespace `nlohmann::literals::json_literals` in 3.11.0. -- Added `char8_t*` overload in 3.12.1. diff --git a/docs/mkdocs/docs/api/operator_literal_json_pointer.md b/docs/mkdocs/docs/api/operator_literal_json_pointer.md index 2c3d6a13a8..423678c77b 100644 --- a/docs/mkdocs/docs/api/operator_literal_json_pointer.md +++ b/docs/mkdocs/docs/api/operator_literal_json_pointer.md @@ -2,7 +2,6 @@ ```cpp json_pointer operator ""_json_pointer(const char* s, std::size_t n); -json_pointer operator ""_json_pointer(const char8_t* s, std::size_t n); // since C++20 ``` This operator implements a user-defined string literal for JSON Pointers. It can be used by adding `#!cpp _json_pointer` @@ -63,4 +62,3 @@ Linear. - Added in version 2.0.0. - Moved to namespace `nlohmann::literals::json_literals` in 3.11.0. -- Added `char8_t*` overload in 3.12.1. diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 284d71c79f..0ef7b43912 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5278,15 +5278,6 @@ inline nlohmann::json operator""_json(const char* s, std::size_t n) return nlohmann::json::parse(s, s + n); } -#if defined(__cpp_char8_t) -JSON_HEDLEY_NON_NULL(1) -inline nlohmann::json operator""_json(const char8_t* s, std::size_t n) -{ - return nlohmann::json::parse(reinterpret_cast(s), - reinterpret_cast(s) + n); -} -#endif - /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) @@ -5295,13 +5286,6 @@ inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std:: return nlohmann::json::json_pointer(std::string(s, n)); } -#if defined(__cpp_char8_t) -inline nlohmann::json::json_pointer operator""_json_pointer(const char8_t* s, std::size_t n) -{ - return nlohmann::json::json_pointer(std::string(reinterpret_cast(s), n)); -} -#endif - } // namespace json_literals } // namespace literals NLOHMANN_JSON_NAMESPACE_END diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 32faa4c5e3..b73783a808 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -25381,15 +25381,6 @@ inline nlohmann::json operator""_json(const char* s, std::size_t n) return nlohmann::json::parse(s, s + n); } -#if defined(__cpp_char8_t) -JSON_HEDLEY_NON_NULL(1) -inline nlohmann::json operator""_json(const char8_t* s, std::size_t n) -{ - return nlohmann::json::parse(reinterpret_cast(s), - reinterpret_cast(s) + n); -} -#endif - /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) @@ -25398,13 +25389,6 @@ inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std:: return nlohmann::json::json_pointer(std::string(s, n)); } -#if defined(__cpp_char8_t) -inline nlohmann::json::json_pointer operator""_json_pointer(const char8_t* s, std::size_t n) -{ - return nlohmann::json::json_pointer(std::string(reinterpret_cast(s), n)); -} -#endif - } // namespace json_literals } // namespace literals NLOHMANN_JSON_NAMESPACE_END diff --git a/tests/src/unit-deserialization.cpp b/tests/src/unit-deserialization.cpp index 0c16afbd78..58fe958ea2 100644 --- a/tests/src/unit-deserialization.cpp +++ b/tests/src/unit-deserialization.cpp @@ -1132,23 +1132,6 @@ TEST_CASE("deserialization") CHECK(object_count == 4); } } - - // build with C++20 - // JSON_HAS_CPP_20 -#if defined(__cpp_char8_t) - SECTION("Using _json with char8_t literals #4945") - { - // Regular narrow string literal - auto j1 = R"({"key": "value", "num": 42})"_json; - CHECK(j1["key"] == "value"); - CHECK(j1["num"] == 42); - - // UTF-8 prefixed literal (C++20 and later) - auto j2 = u8R"({"emoji": "😀", "msg": "hello"})"_json; - CHECK(j2["emoji"] == "😀"); - CHECK(j2["msg"] == "hello"); - } -#endif } // select the types to test - char8_t is only available since C++20 if and only diff --git a/tests/src/unit-json_pointer.cpp b/tests/src/unit-json_pointer.cpp index b36331eba3..149eff00a2 100644 --- a/tests/src/unit-json_pointer.cpp +++ b/tests/src/unit-json_pointer.cpp @@ -788,18 +788,4 @@ TEST_CASE("JSON pointers") CHECK_FALSE(ptr_oj != ptr); } } - - // build with C++20 - // JSON_HAS_CPP_20 -#if defined(__cpp_char8_t) - SECTION("Using _json_pointer with char8_t literals #4945") - { - const json j = R"({"a": {"b": {"c": 123}}})"_json; - const auto p1 = "/a/b/c"_json_pointer; - CHECK(j[p1] == 123); - - const auto p2 = u8"/a/b/c"_json_pointer; - CHECK(j[p2] == 123); - } -#endif } From 7fc3bea9b3354268ad4de28eada0d1de650f647c Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 22 Oct 2025 21:26:38 +0200 Subject: [PATCH 4/5] :green_heart: add code for GCC 4.8 Signed-off-by: Niels Lohmann --- include/nlohmann/json.hpp | 14 ++++++++++++-- single_include/nlohmann/json.hpp | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0ef7b43912..f252fca567 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5273,7 +5273,12 @@ inline namespace json_literals /// @brief user-defined string literal for JSON values /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ JSON_HEDLEY_NON_NULL(1) -inline nlohmann::json operator""_json(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + inline nlohmann::json operator""_json(const char* s, std::size_t n) +#else + // GCC 4.8 requires a space between "" and suffix + inline nlohmann::json operator"" _json(const char* s, std::size_t n) +#endif { return nlohmann::json::parse(s, s + n); } @@ -5281,7 +5286,12 @@ inline nlohmann::json operator""_json(const char* s, std::size_t n) /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) -inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) +#else + // GCC 4.8 requires a space between "" and suffix + inline nlohmann::json::json_pointer operator"" _json_pointer(const char* s, std::size_t n) +#endif { return nlohmann::json::json_pointer(std::string(s, n)); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index b73783a808..2cf666ac2b 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -25376,7 +25376,12 @@ inline namespace json_literals /// @brief user-defined string literal for JSON values /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ JSON_HEDLEY_NON_NULL(1) -inline nlohmann::json operator""_json(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + inline nlohmann::json operator""_json(const char* s, std::size_t n) +#else + // GCC 4.8 requires a space between "" and suffix + inline nlohmann::json operator"" _json(const char* s, std::size_t n) +#endif { return nlohmann::json::parse(s, s + n); } @@ -25384,7 +25389,12 @@ inline nlohmann::json operator""_json(const char* s, std::size_t n) /// @brief user-defined string literal for JSON pointer /// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) -inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) +#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + inline nlohmann::json::json_pointer operator""_json_pointer(const char* s, std::size_t n) +#else + // GCC 4.8 requires a space between "" and suffix + inline nlohmann::json::json_pointer operator"" _json_pointer(const char* s, std::size_t n) +#endif { return nlohmann::json::json_pointer(std::string(s, n)); } From 81d859f5a93241405ffef811338d0ce931191597 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 22 Oct 2025 22:11:18 +0200 Subject: [PATCH 5/5] :green_heart: add code for GCC 4.8 Signed-off-by: Niels Lohmann --- include/nlohmann/json.hpp | 10 ++++++++-- single_include/nlohmann/json.hpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index f252fca567..f86e8d4944 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5355,8 +5355,14 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC } // namespace std #if JSON_USE_GLOBAL_UDLS - using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) + using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #else + // GCC 4.8 requires a space between "" and suffix + using nlohmann::literals::json_literals::operator"" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) + using nlohmann::literals::json_literals::operator"" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #endif #endif #include diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 2cf666ac2b..1f2fcfccd5 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -25458,8 +25458,14 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC } // namespace std #if JSON_USE_GLOBAL_UDLS - using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) - using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) + using nlohmann::literals::json_literals::operator""_json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) + using nlohmann::literals::json_literals::operator""_json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #else + // GCC 4.8 requires a space between "" and suffix + using nlohmann::literals::json_literals::operator"" _json; // NOLINT(misc-unused-using-decls,google-global-names-in-headers) + using nlohmann::literals::json_literals::operator"" _json_pointer; //NOLINT(misc-unused-using-decls,google-global-names-in-headers) + #endif #endif // #include