I have a working example program which parses ini formatted data with boost property_tree. When I append a comment to the key-value pairs I get coredump. I have searched any comment trim function on property_tree but cannot find anything.
The working program:
static std::string inidata =
R"(
# comment
[SECTION1]
key1 = 15
key2=val
)";
void read_data(std::istream &is)
{
using boost::property_tree::ptree;
ptree pt;
read_ini(is, pt);
boost::optional<uint32_t> sect1_key1 = pt.get_optional<uint32_t>(ptree::path_type("SECTION1/key1", '/'));
boost::optional<std::string> sect1_key2 = pt.get_optional<std::string>(ptree::path_type("SECTION1/key2", '/'));
std::cout << "SECTION1.key1: " << *sect1_key1 << std::endl;
std::cout << "SECTION1.key2: " << *sect1_key2 << std::endl;
}
The comment appended config:
static std::string inidata =
R"(
# comment
[SECTION1]
key1 = 15 # COMMENT ADDED!
key2=val
)";
The core dump output:
/usr/local/include/boost/optional/optional.hpp:992: boost::optional<T>::reference_type boost::optional<T>::get() [with T = unsigned int; boost::optional<T>::reference_type = unsigned int&]: Assertion `this->is_initialized()' failed.
Aborted (core dumped)