From a43bad747afc276496592ad6a8bc6253ca51761e Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 17 Oct 2026 14:21:09 +0200 Subject: [PATCH] Rename emit() in the view builder for Qt compatibility Qt defines emit as an empty macro, so a Qt header included before json_view.hpp broke the declaration of the builder's emit(), see issue #5865. It is now called push_node(). Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/builder.hpp | 14 +++++++------- single_include/nlohmann/json_view.hpp | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/nlohmann/detail/view/builder.hpp b/include/nlohmann/detail/view/builder.hpp index fab8bccb1..11187a947 100644 --- a/include/nlohmann/detail/view/builder.hpp +++ b/include/nlohmann/detail/view/builder.hpp @@ -829,7 +829,7 @@ indent_done: /// append a node: (kind, flags, extra, off) and the second word (len, or /// an integer's value); two stores on little-endian targets - NLOHMANN_VIEW_ALWAYS_INLINE node* emit(value_t k, std::uint8_t flags, std::uint16_t extra, std::size_t off, std::uint64_t second) + NLOHMANN_VIEW_ALWAYS_INLINE node* push_node(value_t k, std::uint8_t flags, std::uint16_t extra, std::size_t off, std::uint64_t second) { if (NLOHMANN_VIEW_UNLIKELY(out == cap)) { @@ -859,9 +859,9 @@ indent_done: NLOHMANN_VIEW_ALWAYS_INLINE void open(value_t k) { - // (base is read after emit(), which moves the node array when it + // (base is read after push_node(), which moves the node array when it // grows; in one expression the order of the two is unspecified) - const node* const n = emit(k, 0, 0, static_cast(p - b), 0); + const node* const n = push_node(k, 0, 0, static_cast(p - b), 0); const auto idx = static_cast(n - base); if (depth != 0) { @@ -914,7 +914,7 @@ indent_done: { return fail(error_code::invalid_literal); } - emit(k, flags, 0, static_cast(p - b), n); + push_node(k, flags, 0, static_cast(p - b), n); p += n; return true; } @@ -1022,7 +1022,7 @@ indent_done: // of the negative std::int64_t) second = negative ? 0 - m : m; } - emit(kind, 0, layout, static_cast(s - b), second); + push_node(kind, 0, layout, static_cast(s - b), second); return true; } @@ -1034,7 +1034,7 @@ indent_done: p = scan_string_run(p, e); if (NLOHMANN_VIEW_LIKELY(p != e && *p == '"')) { - emit(value_t::string, 0, 0, static_cast(s - b), static_cast(p - s)); + push_node(value_t::string, 0, 0, static_cast(s - b), static_cast(p - s)); ++p; return true; } @@ -1044,7 +1044,7 @@ indent_done: return false; } p = r.p; - emit(value_t::string, node_flags::escaped, 0, r.start, r.len); + push_node(value_t::string, node_flags::escaped, 0, r.start, r.len); return true; } }; diff --git a/single_include/nlohmann/json_view.hpp b/single_include/nlohmann/json_view.hpp index 1527d7f29..26e30cbbb 100644 --- a/single_include/nlohmann/json_view.hpp +++ b/single_include/nlohmann/json_view.hpp @@ -1453,7 +1453,7 @@ indent_done: /// append a node: (kind, flags, extra, off) and the second word (len, or /// an integer's value); two stores on little-endian targets - NLOHMANN_VIEW_ALWAYS_INLINE node* emit(value_t k, std::uint8_t flags, std::uint16_t extra, std::size_t off, std::uint64_t second) + NLOHMANN_VIEW_ALWAYS_INLINE node* push_node(value_t k, std::uint8_t flags, std::uint16_t extra, std::size_t off, std::uint64_t second) { if (NLOHMANN_VIEW_UNLIKELY(out == cap)) { @@ -1483,9 +1483,9 @@ indent_done: NLOHMANN_VIEW_ALWAYS_INLINE void open(value_t k) { - // (base is read after emit(), which moves the node array when it + // (base is read after push_node(), which moves the node array when it // grows; in one expression the order of the two is unspecified) - const node* const n = emit(k, 0, 0, static_cast(p - b), 0); + const node* const n = push_node(k, 0, 0, static_cast(p - b), 0); const auto idx = static_cast(n - base); if (depth != 0) { @@ -1538,7 +1538,7 @@ indent_done: { return fail(error_code::invalid_literal); } - emit(k, flags, 0, static_cast(p - b), n); + push_node(k, flags, 0, static_cast(p - b), n); p += n; return true; } @@ -1646,7 +1646,7 @@ indent_done: // of the negative std::int64_t) second = negative ? 0 - m : m; } - emit(kind, 0, layout, static_cast(s - b), second); + push_node(kind, 0, layout, static_cast(s - b), second); return true; } @@ -1658,7 +1658,7 @@ indent_done: p = scan_string_run(p, e); if (NLOHMANN_VIEW_LIKELY(p != e && *p == '"')) { - emit(value_t::string, 0, 0, static_cast(s - b), static_cast(p - s)); + push_node(value_t::string, 0, 0, static_cast(s - b), static_cast(p - s)); ++p; return true; } @@ -1668,7 +1668,7 @@ indent_done: return false; } p = r.p; - emit(value_t::string, node_flags::escaped, 0, r.start, r.len); + push_node(value_t::string, node_flags::escaped, 0, r.start, r.len); return true; } };