From ef1e256fa77399b45037d20c6577a18eb54cb3bf Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Thu, 25 Feb 2021 08:50:57 -0500 Subject: [PATCH] Workaround for SIMDJSON_ASSUME "side-effect" warning under some compilers. (#1456) --- include/simdjson/generic/ondemand/json_iterator-inl.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/simdjson/generic/ondemand/json_iterator-inl.h b/include/simdjson/generic/ondemand/json_iterator-inl.h index 86ed9c09..2bab349c 100644 --- a/include/simdjson/generic/ondemand/json_iterator-inl.h +++ b/include/simdjson/generic/ondemand/json_iterator-inl.h @@ -146,8 +146,12 @@ simdjson_really_inline uint32_t json_iterator::peek_length(token_position positi } simdjson_really_inline token_position json_iterator::last_document_position() const noexcept { - SIMDJSON_ASSUME(parser->implementation->n_structural_indexes > 0); - return &parser->implementation->structural_indexes[parser->implementation->n_structural_indexes - 1]; + // The following line fails under some compilers... + // SIMDJSON_ASSUME(parser->implementation->n_structural_indexes > 0); + // since it has side-effects. + uint32_t n_structural_indexes{parser->implementation->n_structural_indexes}; + SIMDJSON_ASSUME(n_structural_indexes > 0); + return &parser->implementation->structural_indexes[n_structural_indexes - 1]; } simdjson_really_inline const uint8_t *json_iterator::peek_last() const noexcept { return token.peek(last_document_position());