Boost C++ Libraries: Ticket #11599: VS2015 warns that in new_tree, not all control paths return a value https://svn.boost.org/trac10/ticket/11599 <p> 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: </p> <p> warning C4715: 'boost::property_tree::json_parser::detail::standard_callbacks&lt;boost::property_tree::basic_ptree&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::less&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &gt; &gt; &gt;::new_tree': not all control paths return a value </p> <p> 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: </p> <blockquote> <p> default: </p> <blockquote> <p> assert(l.k == leaf); stack.pop_back(); return new_tree(); </p> </blockquote> <p> } </p> </blockquote> <blockquote> <p> } </p> </blockquote> <p> This warning appears for both Debug and Release builds. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11599 Trac 1.4.3 anonymous Wed, 28 Oct 2015 21:27:46 GMT <link>https://svn.boost.org/trac10/ticket/11599#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:1</guid> <description> <p> 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? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 08 Dec 2015 16:28:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11599#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:2</guid> <description> <p> Same here! </p> <p> thanks </p> </description> <category>Ticket</category> </item> <item> <author>alister_fong@…</author> <pubDate>Wed, 23 Dec 2015 02:20:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11599#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:3</guid> <description> <p> This appears for VS2010 using Boost 1.60 as well. Thank you. </p> </description> <category>Ticket</category> </item> <item> <author>stephan.menzel@…</author> <pubDate>Mon, 29 Feb 2016 14:16:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11599#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:4</guid> <description> <p> Confirmed. Also the case for MSVC14 and 1.60. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sebastian Redl</dc:creator> <pubDate>Tue, 01 Mar 2016 15:31:26 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11599#comment:5 https://svn.boost.org/trac10/ticket/11599#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> 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). </p> Ticket anonymous Wed, 11 May 2016 08:42:20 GMT <link>https://svn.boost.org/trac10/ticket/11599#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/11599#comment:5" title="Comment 5">cornedbee</a>: </p> <blockquote class="citation"> <p> 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). </p> </blockquote> <p> I think this is an error because assert does nothing if NDEBUG is defined. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>JM Volle</dc:creator> <pubDate>Wed, 11 May 2016 11:47:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11599#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:7</guid> <description> <p> In case it helps, what I did (warning seen with VS2015) to suppress the warning is simply add: </p> <pre class="wiki">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&amp; new_value() { if (stack.empty()) return new_tree().data(); -- </pre> </description> <category>Ticket</category> </item> <item> <author>Edward Brey <edward@…></author> <pubDate>Wed, 11 May 2016 18:33:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11599#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:8</guid> <description> <p> 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? </p> </description> <category>Ticket</category> </item> <item> <author>stephan.menzel@…</author> <pubDate>Wed, 11 May 2016 18:38:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11599#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11599#comment:9</guid> <description> <p> Well, wouldn't it sort of achieve the desired effect to make object: the default? </p> </description> <category>Ticket</category> </item> </channel> </rss>