Files
simdjson-simdjson/tests/compilation_failure_tests/dangling_parser_parse_uint8.cpp
Paul Dreik 75545ff70d 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.
2020-04-15 09:57:52 +02:00

18 lines
447 B
C++

// this tests https://github.com/simdjson/simdjson/issues/696
#include <iostream>
#include "simdjson.h"
int main() {
const uint8_t buf[128]={};
const size_t len=sizeof(buf);
#if COMPILATION_TEST_USE_FAILING_CODE
simdjson::dom::element tree = simdjson::dom::parser().parse(buf,len);
#else
simdjson::dom::parser parser;
simdjson::dom::element tree = parser.parse(buf,len);
#endif
std::cout << tree["type"] << std::endl;
}