2
votes

I have the following code:

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>

#include <sstream>
#include <string>

int main()
{
  std::string input("{\"foo\":\"bar\"}");

  boost::property_tree::ptree pt;
  std::stringstream stream;
  stream << input;

  boost::property_tree::read_json(stream, pt);
}

In MSVC-11.0 with boost 1.54 this code compiles fine, but in gcc 4.7.2 with boost 1.49 this code gives me the following errors:

In file included from /usr/include/boost/property_tree/json_parser.hpp:14:0, from main.cpp:1: /usr/include/boost/property_tree/detail/json_parser_read.hpp: In instantiation of ‘void boost::property_tree::json_parser::context::a_literal_val::operator()(boost::property_tree::json_parser::context::It, boost::property_tree::json_parser::context::It) const [with Ptree = boost::property_tree::basic_ptree, std::basic_string >; boost::property_tree::json_parser::context::It = __gnu_cxx::__normal_iterator > >]’: /usr/include/boost/spirit/home/classic/core/scanner/scanner.hpp:148:13: required from ‘static void boost::spirit::classic::attributed_action_policy::call(const ActorT&, boost::spirit::classic::nil_t, const IteratorT&, const IteratorT&) [with ActorT = boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val; IteratorT = __gnu_cxx::__normal_iterator > >]’ /usr/include/boost/spirit/home/classic/core/scanner/scanner.hpp:163:13: required from ‘void boost::spirit::classic::action_policy::do_action(const ActorT&, AttrT&, const IteratorT&, const IteratorT&) const [with ActorT = boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val; AttrT = boost::spirit::classic::nil_t; IteratorT = __gnu_cxx::__normal_iterator > >]’ /usr/include/boost/spirit/home/classic/core/composite/actions.hpp:116:17: required from ‘typename boost::spirit::classic::parser_result, ScannerT>::type boost::spirit::classic::action::parse(const ScannerT&) const [with ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme>

, boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; ParserT = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >; ActionT = boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val; typename boost::spirit::classic::parser_result, ScannerT>::type = boost::spirit::classic::match]’ /usr/include/boost/spirit/home/classic/core/composite/alternative.hpp:67:59: recursively required from ‘typename boost::spirit::classic::parser_result, ScannerT>::type boost::spirit::classic::alternative::parse(const ScannerT&) const [with ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; A = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::property_tree::json_parser::context, std::basic_string > >::a_string_val>, boost::spirit::classic::action > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val> >; B = boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>; typename boost::spirit::classic::parser_result, ScannerT>::type = boost::spirit::classic::match]’ /usr/include/boost/spirit/home/classic/core/composite/alternative.hpp:67:59: required from ‘typename boost::spirit::classic::parser_result, ScannerT>::type boost::spirit::classic::alternative::parse(const ScannerT&) const [with ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; A = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::property_tree::json_parser::context, std::basic_string > >::a_string_val>, boost::spirit::classic::action > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val> >, boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t> >; B = boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>; typename boost::spirit::classic::parser_result, ScannerT>::type = boost::spirit::classic::match]’ /usr/include/boost/spirit/home/classic/core/non_terminal/impl/rule.ipp:240:36: required from ‘typename boost::spirit::classic::match_result::type boost::spirit::classic::impl::concrete_parser::do_parse_virtual(const ScannerT&) const [with ParserT = boost::spirit::classic::alternative > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::property_tree::json_parser::context, std::basic_string > >::a_string_val>, boost::spirit::classic::action > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t>, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::spirit::classic::strlit >, boost::property_tree::json_parser::context, std::basic_string > >::a_literal_val> >, boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t> >, boost::spirit::classic::rule > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >, boost::spirit::classic::nil_t, boost::spirit::classic::nil_t> >; ScannerT = boost::spirit::classic::scanner<__gnu_cxx::__normal_iterator > >, boost::spirit::classic::scanner_policies, boost::spirit::classic::kleene_star, boost::spirit::classic::alternative, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::confix_parser, boost::spirit::classic::kleene_star, boost::spirit::classic::strlit, boost::spirit::classic::unary_parser_category, boost::spirit::classic::non_nested, boost::spirit::classic::is_lexeme> , boost::spirit::classic::iteration_policy>, boost::spirit::classic::match_policy, boost::spirit::classic::action_policy> >; AttrT = boost::spirit::classic::nil_t; typename boost::spirit::classic::match_result::type = boost::spirit::classic::match]’ main.cpp:16:1: required from here /usr/include/boost/property_tree/detail/json_parser_read.hpp:105:17: error: no matching function for call to ‘boost::property_tree::basic_ptree, std::basic_string ::push_back(std::pair, std::basic_string >)’ /usr/include/boost/property_tree/detail/json_parser_read.hpp:105:17: note: candidate is: In file included from /usr/include/boost/property_tree/ptree.hpp:516:0, from /usr/include/boost/property_tree/json_parser.hpp:13, from main.cpp:1: /usr/include/boost/property_tree/detail/ptree_implementation.hpp:362:9: note: boost::property_tree::basic_ptree::iterator boost::property_tree::basic_ptree::push_back(const value_type&) [with Key = std::basic_string; Data = std::basic_string; KeyCompare = std::less >; boost::property_tree::basic_ptree::value_type = std::pair, boost::property_tree::basic_ptree, std::basic_string > >] /usr/include/boost/property_tree/detail/ptree_implementation.hpp:362:9: note: no known conversion for argument 1 from ‘std::pair, std::basic_string >’ to ‘const value_type& {aka const std::pair, boost::property_tree::basic_ptree, std::basic_string > >&}’

What am I doing wrong? How can I fix it?

1
Your error message is corrupted beyond comprehensibility. They key part starts close to the bottom, at "/usr/include/boost/property_tree/detail/json_parser_read.hpp:105:17: error: no matching function ", but the stuff it lists doesn't make any sense.Sebastian Redl
@Sebastian Redl Yep, i already saw it, but according to the documentation, such function exists in boost 1.49 - boost.org/doc/libs/1_49_0/boost/property_tree/json_parser.hppFrozenHeart
The error refers to the internals of the library. I'm trying to find out what happened, but can't because the message is garbled.Sebastian Redl
@Sebastian Redl Unfortunately, I don't have any additional infoFrozenHeart
I just noticed that I can compile this code when I use -std=c++98 and not -std=c++11FrozenHeart

1 Answers

2
votes

As mentioned in the comments on OP's question, boost 1.49 does not compile with c++11 when boost::property_tree::read_json is used. It's a known bug, and is solved by either using a more recent version of boost, or applying the the following patch:

--- json_parser_read.hpp        2013-09-01 03:55:57.000000000 +0400
+++ /usr/include/boost/property_tree/detail/json_parser_read.hpp        2013-09-01 03:56:21.000000000 +0400
@@ -102,7 +102,7 @@
             void operator()(It b, It e) const
             {
                 BOOST_ASSERT(c.stack.size() >= 1);
-                c.stack.back()->push_back(std::make_pair(c.name, Str(b, e)));
+                c.stack.back()->push_back(std::make_pair(c.name, Ptree(Str(b, e))));
                 c.name.clear();
                 c.string.clear();
             }

or

sed -i -e 's/std::make_pair(c.name, Str(b, e))/std::make_pair(c.name, Ptree(Str(b, e)))/' json_parser_read.hpp

described here.