[英]Boost json_parser warning C4715
I'm trying to save some data from string in boost::property_tree:ptree
object: 我正在尝试从
boost::property_tree:ptree
对象中的字符串中保存一些数据:
const char* data = "Here are json params";
boost:property_tree:ptree tr;
std::stringstream ss;
ss << data;
//Here i get warning
boost::property_tree:ptree::read_json(ss, tr);
Warning is following: 警告如下:
boost\property_tree\detail\json_parser\standard_callbacks.hpp(132): warning C4715: 'boost::property_tree::json_parser::detail::standard_callbacks<boost::property_tree::basic_ptree<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > >::new_tree' : not all control paths return a value
Can anyone help me fix this problem? 谁能帮我解决这个问题?
It isn't a problem. 没问题 It has to do with Boost, not your code.
它与Boost有关,与您的代码无关。 You can ignore the warning or suppress it in your IDE if you wish.
您可以忽略该警告,也可以在IDE中取消显示该警告。 The error is
Ptree& new_tree
technically can finish without a return
statement. 错误是
Ptree& new_tree
技术上讲可以在没有return
语句的情况下完成。 Here's the code: 这是代码:
Ptree& new_tree() {
if (stack.empty()) {
layer l = {leaf, &root};
stack.push_back(l);
return root;
}
layer& l = stack.back();
switch (l.k) {
case array: {
l.t->push_back(std::make_pair(string(), Ptree()));
layer nl = {leaf, & l.t->back().second};
stack.push_back(nl);
return *stack.back().t;
}
case object:
default:
BOOST_ASSERT(false); // must start with string, i.e. call new_value
case key: {
l.t->push_back(std::make_pair(key_buffer, Ptree()));
l.k = object;
layer nl = {leaf, &l.t->back().second};
stack.push_back(nl);
return *stack.back().t;
}
case leaf:
stack.pop_back();
return new_tree();
}
}
As you can see, in the switch there's a default: BOOST_ASSERT(false)
which means while the function doesn't return anything, it also triggers your debugger to immediately stop because something went horribly wrong. 如您所见,在该开关中有一个
default: BOOST_ASSERT(false)
,这意味着尽管该函数不返回任何内容,但它也会触发调试器立即停止,因为发生了严重错误。 Your compiler isn't clever enough to figure it by itself, so it warns you. 您的编译器不够聪明,无法自行解决,因此会警告您。 In this case you can definitely ignore the warning.
在这种情况下,您绝对可以忽略该警告。
The function contains a switch
with one case being 该功能包含一个
switch
,其中一种情况是
default:
BOOST_ASSERT(false); // must start with string, i.e. call new_value
Arguably this part doesn't return a value, but mostly because it doesn't return at all. 可以说这部分不返回值,但是主要是因为它根本不返回。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.