diff --git a/include/nlohmann/detail/view/builder.hpp b/include/nlohmann/detail/view/builder.hpp index ccb54c3d7..6bd48943c 100644 --- a/include/nlohmann/detail/view/builder.hpp +++ b/include/nlohmann/detail/view/builder.hpp @@ -821,7 +821,10 @@ indent_done: NLOHMANN_VIEW_ALWAYS_INLINE void open(value_t k) { - const auto idx = static_cast(emit(k, 0, 0, static_cast(p - b), 0) - base); + // (base is read after emit(), 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 auto idx = static_cast(n - base); if (depth != 0) { const frame f = {cur_idx, cur_count, cur_is_object};