boostorg / parser

A C++ parser combinator library.
Boost Software License 1.0
87 stars 12 forks source link

string_parser needs to initialize success flag #185

Closed cppljevans closed 3 weeks ago

cppljevans commented 2 months ago

The string_parser::call needs to initialize the success out value to true.

Here, in the string_parser::call function:

https://github.com/tzlaine/parser/blob/develop/include/boost/parser/parser.hpp#L6913

the only change to the success flag is to false. This is definitely wrong. It needs to be initialized to true at the start of the function. Otherwise, if the success flag is passed as false, it will not change its value, despite the parse being successful.

tzlaine commented 3 weeks ago

Setting the status to true would be superfluous. It is a precondition of each parser that success == true. success is a bool &. If we got into any parser and it were not true, that would mean that the parse failed, and yet the caller decided to start a new parse. That doesn't happen. for obvious reasons.