Closed dvirtz closed 5 years ago
it should be
std::basic_string<Char>
instead ofChar const*
No, it must not. At least not in your example (see explanation in the end).
currently the parser stores a pointer to the string buffer
That's right.
which goes out of scope.
Not the pointer, but the string itself.
Recap: You are binding to a temporary string that will be out of scope (already destroyed) by the time when you are invoking the parser. With Qi you have the same bug in your program, but do not observe the problem just by luck. It is your fault, and unfortunately compilers do not do deep object lifetime analysis (it can change in future, see Herb Sutter talk), but you can use AddressSanitize to catch those bugs at run-time.
Rationale: If you are passing a string object to Spirit it has to be generated at run-time and most of the users obviously do not want to have unneeded copy operation (that's why I am sure that #175 was wrong).
Probably, we should move-in and store user string if it was passed by rvalue, but you did not pass your string as an rvalue.
https://wandbox.org/permlink/qSp4Kkb1bLd5rl0u:
It seems the cause is at https://github.com/boostorg/spirit/blob/b023ffa272b115815b6e714f8cc43bb9e09a9e14/include/boost/spirit/home/x3/string/literal_string.hpp#L231 where it should be
std::basic_string<Char>
instead ofChar const*
, as currently the parser stores a pointer to the string buffer which goes out of scope.The same code passes without problems with qi: https://wandbox.org/permlink/6xLC19SSZXQXjCp5