mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Fix initialization order in auto_parser constructor
The issue was that we were calling m_parser.iterate() after moving the parser, which could leave it in an invalid state. In C++20, this might behave differently than C++17. Fixed by reordering the member initializer list to call parser.iterate() BEFORE moving the parser into m_parser. This ensures the document is created while the parser is still valid. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -106,7 +106,8 @@ public:
|
||||
explicit auto_parser(ParserType &&parser,
|
||||
padded_string_view const str) noexcept
|
||||
requires(!std::is_pointer_v<ParserType>)
|
||||
: m_parser{std::move(parser)}, m_doc(m_parser.iterate(str)) {}
|
||||
// Note: order matters! We need to call iterate BEFORE moving the parser
|
||||
: m_doc(parser.iterate(str)), m_parser{std::move(parser)} {}
|
||||
|
||||
explicit auto_parser(padded_string_view const str) noexcept
|
||||
requires(!std::is_pointer_v<ParserType>)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* auto-generated on 2025-08-03 15:28:40 +0000. Do not edit! */
|
||||
/* auto-generated on 2025-08-03 18:12:50 +0000. Do not edit! */
|
||||
/* including simdjson.cpp: */
|
||||
/* begin file simdjson.cpp */
|
||||
#define SIMDJSON_SRC_SIMDJSON_CPP
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* auto-generated on 2025-08-03 15:28:40 +0000. Do not edit! */
|
||||
/* auto-generated on 2025-08-03 18:12:50 +0000. Do not edit! */
|
||||
/* including simdjson.h: */
|
||||
/* begin file simdjson.h */
|
||||
#ifndef SIMDJSON_H
|
||||
@@ -135358,7 +135358,8 @@ public:
|
||||
explicit auto_parser(ParserType &&parser,
|
||||
padded_string_view const str) noexcept
|
||||
requires(!std::is_pointer_v<ParserType>)
|
||||
: m_parser{std::move(parser)}, m_doc(m_parser.iterate(str)) {}
|
||||
// Note: order matters! We need to call iterate BEFORE moving the parser
|
||||
: m_doc(parser.iterate(str)), m_parser{std::move(parser)} {}
|
||||
|
||||
explicit auto_parser(padded_string_view const str) noexcept
|
||||
requires(!std::is_pointer_v<ParserType>)
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user