#11599 closed Bugs (fixed)
VS2015 warns that in new_tree, not all control paths return a value
Reported by: | Owned by: | Sebastian Redl | |
---|---|---|---|
Milestone: | To Be Determined | Component: | property_tree |
Version: | Boost 1.59.0 | Severity: | Problem |
Keywords: | warnings | Cc: |
Description
In standard_callbacks::new_tree, Visual Studio 2015 can't tell from the assert(false) that the method will never exit after the switch statement, and so issues this warning:
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
One solution to eliminate the warning and make the code more performant and, in case of a bug, more repeatable, is to change the end of the method to use this code:
default:
assert(l.k == leaf); stack.pop_back(); return new_tree();
}
}
This warning appears for both Debug and Release builds.
Change History (9)
comment:1 by , 7 years ago
follow-up: 6 comment:5 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In my opinion, VS's warning is broken and I would have loved to be able to use Clang's uncovered-switch warning. But I've bit the sour apple and did this because I couldn't find any nicer way of silencing VS without outright suppressing the warning (and thus adding compiler-specific code).
comment:6 by , 6 years ago
Replying to cornedbee:
In my opinion, VS's warning is broken and I would have loved to be able to use Clang's uncovered-switch warning. But I've bit the sour apple and did this because I couldn't find any nicer way of silencing VS without outright suppressing the warning (and thus adding compiler-specific code).
I think this is an error because assert does nothing if NDEBUG is defined.
comment:7 by , 6 years ago
In case it helps, what I did (warning seen with VS2015) to suppress the warning is simply add:
diff --git a/LIB/CPP_3rdParty/boost/1_60/boost/property_tree/detail/json_parser/standard_callbacks.hpp b/LIB/CPP_3rdParty/boost/1_60/boost/property_tree/detail/json_parser/standard_callbacks.hpp index 56c378e..bfa5374 100644 --- a/LIB/CPP_3rdParty/boost/1_60/boost/property_tree/detail/json_parser/standard_callbacks.hpp +++ b/LIB/CPP_3rdParty/boost/1_60/boost/property_tree/detail/json_parser/standard_callbacks.hpp @@ -129,6 +129,8 @@ namespace boost { namespace property_tree { return new_tree(); } assert(false); + throw(std::logic_error("reached passed assert!")); + } string& new_value() { if (stack.empty()) return new_tree().data(); --
comment:8 by , 6 years ago
Adding a throw with a custom string runs mildly contrary to the C++ tradition of "don't pay for what you don't use". In this case, everyone knows that the code will never be called - but not the compiler, which will do its duty to use the necessary code space, with its accompanying penalties for load time and cache hit rate. Any thought of my original suggestion of just making the one of the cases be the default?
comment:9 by , 6 years ago
Well, wouldn't it sort of achieve the desired effect to make object: the default?
This warning occurs in VS2010 as well. This becomes an even bigger problem when you treat warnings as errors. Can you put in something to fix this please?