mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
ref qualify parser methods to avoid use of dangling objects (#703)
To avoid using data belonging to a temporary, the parse functions are ref qualified to get a compile error if used on an rvalue. See https://github.com/simdjson/simdjson/issues/696 Compilation tests are also added, to make sure bad usage fails to compile. Reviewed by jkeiser.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
|
||||
// this tests https://github.com/simdjson/simdjson/issues/696
|
||||
|
||||
#include <iostream>
|
||||
#include "simdjson.h"
|
||||
|
||||
int main() {
|
||||
std::string buf;
|
||||
#if COMPILATION_TEST_USE_FAILING_CODE
|
||||
simdjson::dom::element tree = simdjson::dom::parser().parse(buf);
|
||||
#else
|
||||
simdjson::dom::parser parser;
|
||||
simdjson::dom::element tree = parser.parse(buf);
|
||||
#endif
|
||||
std::cout << tree["type"] << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user