Opened 13 years ago

Closed 13 years ago

#3437 closed Bugs (fixed)

Unreachable code warning in Boost::property_tree macro

Reported by: Scott Bailey <Bailey@…> Owned by: Sebastian Redl
Milestone: Boost 1.41.0 Component: property_tree
Version: Boost 1.40.0 Severity: Problem
Keywords: ptree. unreachable code Cc: Scott, Bailey, <Bailey@…>, mateusz@…

Description

The BOOST_PROPERTY_TREE_THROW macro us defined as follows:

    // Throwing macro to avoid no return warnings portably
#   define BOOST_PROPERTY_TREE_THROW(e) { throw_exception(e);  std::exit(1); }

When using MSVS v8.0 with warning level 4, this line generates warning 4702, unreachable code.

Why This Matters

Although much of warning level 4 is arguably MORE than necessary, unreachable code warnings can help find code one thought should execute, as well as trim code the indeed is unreachable. This warning should NOT, in my opinion, be disabled project wide, unlike certain other level 4 warnings. Further, I prefer to set warnings as errors to ensure I follow my own advice.

Where

The source of this defect is the BOOST_PROPERTY_TREE_THROW macro, found in property_tree/ptree_fwd.hpp, v55966, on line 139.

Link: [source:trunk/boost/property_tree/ptree_fwd.hpp@55966#L139]

Possible Resolutions

For whatever reason -- although I assume it is related to templates -- # pragma warning(disable: 4702) won't disable this warning, which essentially means the offending unreachable code must be removed; however, I think it's there to provide an exit when exceptions are disabled. Would it be better to provide a different macros based on exception state? I believe this is how MS implements this for the STL...

Perhaps [source:trunk/boost/throw_exception.hpp boost/throw_exception.hpp] should be evaluated? If only for the BOOST_NO_EXCEPTIONS macro.

Recreating

Recreation can be done as follows:

  • Open MSVS
  • Create a new console app
  • add "existing" file [source:trunk/lib/property_tree/examples/debug_settings.cpp@55966] to the project
  • add include of stdafx.h to debug_settings.cpp
  • set properties:
    • warning level 4
    • warnings as errors
    • add boost location to the include search path
  • build the project

Change History (3)

comment:1 by mloskot <mateusz@…>, 13 years ago

Cc: Scott Bailey <Bailey@…> mateusz@… added; Scott Bailey <Bailey@…> removed

comment:2 by Sebastian Redl, 13 years ago

Owner: changed from kaalus to Sebastian Redl
Status: newassigned

comment:3 by Sebastian Redl, 13 years ago

Resolution: fixed
Status: assignedclosed

Changed BOOST_PROPERTY_TREE_THROW to be an alias for BOOST_THROW_EXCEPTION. If that macro causes warnings, at least there's a central place to fix them.

Note: See TracTickets for help on using tickets.