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:
Francisco Geiman Thiesen
2025-08-03 18:36:14 +00:00
parent 248d4eb2aa
commit a7c95e9cc8
4 changed files with 6 additions and 4 deletions
+2 -1
View File
@@ -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 -1
View File
@@ -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
+3 -2
View File
@@ -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.