I'm using boost 1.57.
I need to disable exception support in my not widely-used proprietary compiler.
When I needed to use boost::smart_ptr
, the following steps worked like a charm:
Disabled C++11 support using the following
user.hpp
file (compiling with-DBOOST_USER_CONFIG="<user.hpp>"
):#define BOOST_HAS_NRVO #define BOOST_NO_COMPLETE_VALUE_INITIALIZATION #define BOOST_NO_CXX11_AUTO_DECLARATIONS #define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS #define BOOST_NO_CXX11_CHAR16_T #define BOOST_NO_CXX11_CHAR32_T #define BOOST_NO_CXX11_CONSTEXPR #define BOOST_NO_CXX11_DECLTYPE #define BOOST_NO_CXX11_DECLTYPE_N3276 #define BOOST_NO_CXX11_DEFAULTED_FUNCTIONS #define BOOST_NO_CXX11_DELETED_FUNCTIONS #define BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS #define BOOST_NO_CXX11_FINAL #define BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS #define BOOST_NO_CXX11_LAMBDAS #define BOOST_NO_CXX11_LOCAL_CLASS_TEMPLATE_PARAMETERS #define BOOST_NO_CXX11_NOEXCEPT #define BOOST_NO_CXX11_NULLPTR #define BOOST_NO_CXX11_RANGE_BASED_FOR #define BOOST_NO_CXX11_RAW_LITERALS #define BOOST_NO_CXX11_REF_QUALIFIERS #define BOOST_NO_CXX11_RVALUE_REFERENCES #define BOOST_NO_CXX11_SCOPED_ENUMS #define BOOST_NO_CXX11_STATIC_ASSERT #define BOOST_NO_CXX11_TEMPLATE_ALIASES #define BOOST_NO_CXX11_UNICODE_LITERALS #define BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX #define BOOST_NO_CXX11_USER_DEFINED_LITERALS #define BOOST_NO_CXX11_VARIADIC_MACROS #define BOOST_NO_CXX11_VARIADIC_TEMPLATES #define BOOST_NO_SFINAE_EXPR #define BOOST_NO_TWO_PHASE_NAME_LOOKUP
Informs boost libraries not to use exceptions:
-DBOOST_NO_EXCEPTIONS -DBOOST_EXCEPTION_DISABLE
Resulting in the following compilation line:
MyCOMPILER -DBOOST_USER_CONFIG="<user.hpp>" -DBOOST_NO_EXCEPTIONS -DBOOST_EXCEPTION_DISABLE -c Foo.cpp -o Foo.o
Then the following piece of code successfully compiled:
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared.hpp>
namespace boost {
void throw_exception(std::exception const& e) {
std::cerr << "Fake exception: " << e.what() << "\n";
std::exit(255);
}
}
class Foo {
private:
boost::shared_ptr<int> ptr;
public:
bool bar(const std::string file_name) {
ptr = boost::make_shared<int>();
return true;
}
};
But when I've tried to use the above method with the following source code, the compilation goes wrong:
#include <iostream>
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
namespace boost {
void throw_exception(std::exception const& e) {
std::cerr << "Fake exception: " << e.what() << "\n";
std::exit(255);
}
}
class Foo {
public:
bool bar(const std::string file_name) {
boost::property_tree::ptree prop_tree;
boost::property_tree::read_ini(file_name, prop_tree);
return !prop_tree.empty();
}
};
Resulting the following errors for instance:
"boost\boost/optional/optional.hpp", line 1047: Error: #312: no suitable user-defined conversion from "boost::bad_optional_access" to "const std::exception" exists
throw_exception(bad_optional_access());
^
"boost\boost/optional/optional.hpp", line 1055: Error: #312: no suitable user-defined conversion from "boost::bad_optional_access" to "const std::exception" exists
throw_exception(bad_optional_access());
^
"boost\boost/type_index/stl_type_index.hpp", line 138: Error: #312: no suitable user-defined conversion from "std::runtime_error" to "const std::exception" exists
boost::throw_exception(std::runtime_error("Type name demangling failed"));
^
"boost\boost/property_tree/ini_parser.hpp", line 168: Error: #540: support for exception handling is disabled; use --exceptions to enable
try {
^
Finally the question:
Why in the first case all works OK, but not in the second?
How can I get boost::property_tree
to compile properly without exception support? Is this even possible?
来源:https://stackoverflow.com/questions/31406974/disable-exception-working-for-boostsmart-ptr-but-not-for-boostproperty-tree