Отключить исключение, работающее для boost :: smart_ptr, но не для boost :: property_tree

Я использую Boost 1,57.
Мне нужно отключить поддержку исключений в моем не широко используемом проприетарном компиляторе.
Когда мне нужно было использовать boost::smart_ptrСледующие шаги работали как шарм:

  1. Отключена поддержка C ++ 11 с использованием следующего user.hpp файл (компилируется с -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
    
  2. Сообщает буст-библиотекам не использовать исключения: -DBOOST_NO_EXCEPTIONS -DBOOST_EXCEPTION_DISABLE

  3. В результате получается следующая строка компиляции: MyCOMPILER -DBOOST_USER_CONFIG="<user.hpp>" -DBOOST_NO_EXCEPTIONS -DBOOST_EXCEPTION_DISABLE -c Foo.cpp -o Foo.o

Затем следующий фрагмент кода успешно скомпилирован:

#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;
}
};

Но когда я попытался использовать вышеуказанный метод со следующим исходным кодом, компиляция идет не так:

#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();
}
};

В результате следующие ошибки, например:

"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 {
^

Напоследок вопрос:

Почему в первом случае все работает нормально, а во втором нет?
Как я могу получить boost::property_tree правильно скомпилировать без исключения поддержку? Это вообще возможно?

1

Решение

Задача ещё не решена.

Другие решения


По вопросам рекламы ammmcru@yandex.ru
Adblock
detector