Skip to content

trailing commas and comments not working well in some cases #726

@terrywh

Description

@terrywh

Version of Boost

1.79.0

Steps necessary to reproduce the problem

#include <boost/json/parse.hpp>
#include <boost/json/value.hpp>

int main(int argc, char* argv[]) {
    std::string raw = R"([
    "123", // 456
])";
    boost::json::parse_options opt {};
    opt.allow_comments = true;
    opt.allow_trailing_commas = true;
    boost::json::value val = boost::json::parse(raw, {}, opt);
    return 0;
}

compile :

g++ -I /data/vendor/boost-1.79/include -L /data/vendor/boost-1.79/lib test.cpp -lboost_json -lboost_system -o test_json

run the program, and it will terminate with the following:

terminate called after throwing an instance of 'boost::wrapexcept<boost::system::system_error>'
  what():  syntax error [boost.json:1 at ./boost/json/basic_parser_impl.hpp:634 in function 'parse_value']

either remove the comment ("// 456") or the trailing commas, the exception will go away.

All relevant compiler information

gcc/g++ 7.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions