diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec51879..f0d6acd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -136,7 +136,7 @@ jobs: - name: Run tests run: | cd ../boost-root - ./b2 -j3 libs/leaf/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} link=shared,static variant=debug,release,leaf_debug_leaf_hpp,leaf_release_leaf_hpp,leaf_debug_diag0,leaf_release_diag0 + ./b2 -j3 libs/leaf/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} link=shared,static variant=debug,release,leaf_debug_leaf_hpp,leaf_release_leaf_hpp,leaf_debug_diag0,leaf_release_diag0,leaf_debug_embedded,leaf_release_embedded windows: strategy: @@ -185,4 +185,4 @@ jobs: shell: cmd run: | cd ../boost-root - b2 -j3 libs/leaf/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release,leaf_debug_leaf_hpp,leaf_release_leaf_hpp,leaf_debug_diag0,leaf_release_diag0 + b2 -j3 libs/leaf/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release,leaf_debug_leaf_hpp,leaf_release_leaf_hpp,leaf_debug_diag0,leaf_release_diag0,leaf_debug_embedded,leaf_release_embedded diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b644b35..7e218a8 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -76,9 +76,9 @@ "dependsOn": [ "Generate leaf.hpp" ], - "command": "../../b2 test link=shared,static variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=on,off cxxstd=11,14,1z,17 && ../../b2 test link=shared,static variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=off rtti=off", + "command": "../../b2 test link=shared,static variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_embedded,leaf_release_embedded,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=on,off cxxstd=11,14,1z,17 && ../../b2 test link=shared,static variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=off rtti=off", "windows": { - "command": "..\\..\\b2 test variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=on,off && ..\\..\\b2 test variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=off rtti=off", + "command": "..\\..\\b2 test variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_embedded,leaf_release_embedded,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=on,off && ..\\..\\b2 test variant=debug,release,leaf_debug_diag0,leaf_release_diag0,leaf_debug_leaf_hpp,leaf_release_leaf_hpp exception-handling=off rtti=off", }, "problemMatcher": { "base": "$gcc", diff --git a/doc/leaf.adoc b/doc/leaf.adoc index 9b2b93e..4aeb598 100644 --- a/doc/leaf.adoc +++ b/doc/leaf.adoc @@ -2489,6 +2489,9 @@ namespace boost { namespace leaf { <> exception( error_id id ) noexcept; + template + <-deduced>> exception_to_result( F && f ) noexcept; + } } #define BOOST_LEAF_EXCEPTION <> ::boost::leaf::exception @@ -2507,7 +2510,7 @@ Reference: <> | <> | < +.#include ---- namespace boost { namespace leaf { @@ -2515,9 +2518,6 @@ namespace boost { namespace leaf { decltype(std::declval()(std::forward(std::declval())...)) capture(std::shared_ptr && ctx, F && f, A... a); - template - <-deduced>> exception_to_result( F && f ) noexcept; - } } ---- @@ -2967,7 +2967,7 @@ NOTE: To automatically capture `pass:[__FILE__]`, `pass:[__LINE__]` and `pass:[_ === `exception_to_result` [source,c++] -.#include +.#include ---- namespace boost { namespace leaf { @@ -5934,7 +5934,19 @@ The following configuration macros are recognized: * `BOOST_LEAF_DIAGNOSTICS`: Defining this macro to `0` stubs out both <> and <>, which could improve the performance of the error path in some programs (if the macro is left undefined, LEAF defines it as `1`). * `BOOST_LEAF_NO_EXCEPTIONS`: Disables all exception handling support. If left undefined, LEAF defines it based on the compiler configuration (e.g. `-fno-exceptions`). -* `BOOST_LEAF_NO_THREADS`: Disable all multi-thread support. +* `BOOST_LEAF_NO_THREADS`: Disables all multi-thread support. +* `BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR`: Disables the `std::error_code` / `std::error_condition` integration. In this case LEAF does not `#include `, which is considered too heavy for embedded platforms. +* `BOOST_LEAF_DISABLE_STD_STRING`: Disables all use of `std::string` (available only under `BOOST_LEAF_DIAGNOSTICS=0`). In this case LEAF does not `#include ` which is considered too heavy for embedded platforms. + +In addition, defining `BOOST_LEAF_EMBEDDED` is equivalent to the following: + +[source,c++] +---- +#define BOOST_LEAF_NO_EXCEPTIONS +#define BOOST_LEAF_DIAGNOSTICS 0 +#define BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR +#define BOOST_LEAF_DISABLE_STD_STRING +---- == Limitations diff --git a/example/exception_to_result.cpp b/example/exception_to_result.cpp index 443ffb4..7916554 100644 --- a/example/exception_to_result.cpp +++ b/example/exception_to_result.cpp @@ -12,7 +12,6 @@ namespace leaf = boost::leaf; - class error_base: public virtual std::exception { }; class error_a: public virtual error_base { }; class error_b: public virtual error_base { }; diff --git a/include/boost/leaf/capture.hpp b/include/boost/leaf/capture.hpp index 071d56c..750b50c 100644 --- a/include/boost/leaf/capture.hpp +++ b/include/boost/leaf/capture.hpp @@ -235,66 +235,6 @@ future_get( Future & fut ) return future_get_impl(is_result_tag().get())>(), fut); } -//////////////////////////////////////// - -#ifndef BOOST_LEAF_NO_EXCEPTIONS - -template -class result; - -namespace leaf_detail -{ - inline error_id catch_exceptions_helper( std::exception const & ex, leaf_detail_mp11::mp_list<> ) - { - return leaf::new_error(std::current_exception()); - } - - template - inline error_id catch_exceptions_helper( std::exception const & ex, leaf_detail_mp11::mp_list ) - { - if( Ex1 const * p = dynamic_cast(&ex) ) - return catch_exceptions_helper(ex, leaf_detail_mp11::mp_list{ }).load(*p); - else - return catch_exceptions_helper(ex, leaf_detail_mp11::mp_list{ }); - } - - template - struct deduce_exception_to_result_return_type_impl - { - using type = result; - }; - - template - struct deduce_exception_to_result_return_type_impl> - { - using type = result; - }; - - template - using deduce_exception_to_result_return_type = typename deduce_exception_to_result_return_type_impl::type; -} - -template -inline -leaf_detail::deduce_exception_to_result_return_type> -exception_to_result( F && f ) noexcept -{ - try - { - return std::forward(f)(); - } - catch( std::exception const & ex ) - { - return leaf_detail::catch_exceptions_helper(ex, leaf_detail_mp11::mp_list()); - } - catch(...) - { - return leaf::new_error(std::current_exception()); - } -} - -#endif - } } #if defined(_MSC_VER) && !defined(BOOST_LEAF_ENABLE_WARNINGS) /// diff --git a/include/boost/leaf/common.hpp b/include/boost/leaf/common.hpp index 040d84b..203fe0d 100644 --- a/include/boost/leaf/common.hpp +++ b/include/boost/leaf/common.hpp @@ -16,8 +16,11 @@ # endif /// #endif /// -#include -#include +#include +#include +#ifndef BOOST_LEAF_DISABLE_STD_STRING +# include +#endif #include #ifdef _WIN32 # include @@ -34,7 +37,22 @@ namespace boost { namespace leaf { struct BOOST_LEAF_SYMBOL_VISIBLE e_api_function { char const * value; }; -struct BOOST_LEAF_SYMBOL_VISIBLE e_file_name { std::string value; }; +#ifdef BOOST_LEAF_DISABLE_STD_STRING + +struct BOOST_LEAF_SYMBOL_VISIBLE e_file_name +{ + constexpr static char const * const value = ""; + BOOST_LEAF_CONSTEXPR explicit e_file_name( char const * ) { } +}; + +#else + +struct BOOST_LEAF_SYMBOL_VISIBLE e_file_name +{ + std::string value; +}; + +#endif struct BOOST_LEAF_SYMBOL_VISIBLE e_errno { diff --git a/include/boost/leaf/context.hpp b/include/boost/leaf/context.hpp index 2176ef6..0565bae 100644 --- a/include/boost/leaf/context.hpp +++ b/include/boost/leaf/context.hpp @@ -185,7 +185,8 @@ namespace leaf_detail tuple_for_each::propagate_captured(tup, err_id); } - static void print( std::ostream & os, void const * tup, int key_to_print ) + template + static void print( std::basic_ostream & os, void const * tup, int key_to_print ) { BOOST_LEAF_ASSERT(tup != 0); tuple_for_each::print(os, tup, key_to_print); @@ -200,7 +201,8 @@ namespace leaf_detail BOOST_LEAF_CONSTEXPR static void deactivate( Tuple & ) noexcept { } BOOST_LEAF_CONSTEXPR static void propagate( Tuple & tup ) noexcept { } BOOST_LEAF_CONSTEXPR static void propagate_captured( Tuple & tup, int ) noexcept { } - static void print( std::ostream &, void const *, int ) { } + template + BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream &, void const *, int ) { } }; } @@ -365,7 +367,8 @@ public: return is_active_; } - void print( std::ostream & os ) const + template + void print( std::basic_ostream & os ) const { leaf_detail::tuple_for_each::value,Tup>::print(os, &tup_, 0); } @@ -425,7 +428,9 @@ namespace leaf_detail void deactivate() noexcept final override { Ctx::deactivate(); } void propagate() noexcept final override { Ctx::propagate(); } bool is_active() const noexcept final override { return Ctx::is_active(); } +#if BOOST_LEAF_DIAGNOSTICS void print( std::ostream & os ) const final override { return Ctx::print(os); } +#endif }; } diff --git a/include/boost/leaf/detail/config.hpp b/include/boost/leaf/detail/config.hpp index 23cb7b9..c5383d9 100644 --- a/include/boost/leaf/detail/config.hpp +++ b/include/boost/leaf/detail/config.hpp @@ -24,6 +24,19 @@ //////////////////////////////////////// +#ifdef BOOST_LEAF_EMBEDDED +# define BOOST_LEAF_NO_EXCEPTIONS +# define BOOST_LEAF_DIAGNOSTICS 0 +# define BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR +# define BOOST_LEAF_DISABLE_STD_STRING +#endif + +#if BOOST_LEAF_DIAGNOSTICS && defined(BOOST_LEAF_DISABLE_STD_STRING) +# error BOOST_LEAF_DIAGNOSTICS requires the use of std::string +#endif + +//////////////////////////////////////// + // Configure BOOST_LEAF_NO_EXCEPTIONS, unless already #defined #ifndef BOOST_LEAF_NO_EXCEPTIONS diff --git a/include/boost/leaf/detail/demangle.hpp b/include/boost/leaf/detail/demangle.hpp index 4714f5c..d3f7b32 100644 --- a/include/boost/leaf/detail/demangle.hpp +++ b/include/boost/leaf/detail/demangle.hpp @@ -15,8 +15,6 @@ // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt -#include - #ifndef BOOST_LEAF_ENABLE_WARNINGS /// # if defined(_MSC_VER) /// # pragma warning(push,1) /// @@ -27,6 +25,66 @@ # endif /// #endif /// +#include +#include + +namespace boost { namespace leaf { + +namespace leaf_detail +{ + template + BOOST_LEAF_CONSTEXPR inline char const * check_prefix( char const * t, char const (&prefix)[N] ) + { + return std::strncmp(t,prefix,sizeof(prefix)-1)==0 ? t+sizeof(prefix)-1 : t; + } +} + +template +inline char const * type() +{ + using leaf_detail::check_prefix; +char const * t = +#ifdef __FUNCSIG__ + __FUNCSIG__; +#else + __PRETTY_FUNCTION__; +#endif +#if defined(__clang__) + BOOST_LEAF_ASSERT(check_prefix(t,"const char *boost::leaf::type() ")==t+32); + return t+32; +#elif defined(__GNUC__) + BOOST_LEAF_ASSERT(check_prefix(t,"const char* boost::leaf::type() ")==t+32); + return t+32; +#else + char const * clang_style = check_prefix(t,"const char *boost::leaf::type() "); + if( clang_style!=t ) + return clang_style; + char const * gcc_style = check_prefix(t,"const char* boost::leaf::type() "); + if( gcc_style!=t ) + return gcc_style; +#endif + return t; +} + +} } + +//////////////////////////////////////// + +#ifdef BOOST_LEAF_DISABLE_STD_STRING + +namespace boost { namespace leaf { + + inline char const * demangle( char const * name ) + { + return name; + } + +} } + +#else + +#include + #if defined(__has_include) && ((__GNUC__ + 0) >= 5) # if __has_include() # define BOOST_LEAF_HAS_CXXABI_H @@ -81,7 +139,7 @@ namespace leaf_detail scoped_demangled_name& operator= ( scoped_demangled_name const& ) = delete; }; -#if defined( BOOST_LEAF_HAS_CXXABI_H ) +#if defined(BOOST_LEAF_HAS_CXXABI_H) and !defined(BOOST_LEAF_DISABLE_STD_STRING) inline char const * demangle_alloc( char const * name ) noexcept { @@ -129,6 +187,8 @@ namespace leaf_detail # undef BOOST_LEAF_HAS_CXXABI_H #endif +#endif + #if defined(_MSC_VER) && !defined(BOOST_LEAF_ENABLE_WARNINGS) /// #pragma warning(pop) /// #endif /// diff --git a/include/boost/leaf/detail/print.hpp b/include/boost/leaf/detail/print.hpp index 8cf0fc9..92d8cca 100644 --- a/include/boost/leaf/detail/print.hpp +++ b/include/boost/leaf/detail/print.hpp @@ -16,7 +16,7 @@ # endif /// #endif /// -#include +#include #include #include #include @@ -24,42 +24,6 @@ namespace boost { namespace leaf { -namespace leaf_detail -{ - template - BOOST_LEAF_CONSTEXPR inline char const * check_prefix( char const * t, char const (&prefix)[N] ) - { - return std::strncmp(t,prefix,sizeof(prefix)-1)==0 ? t+sizeof(prefix)-1 : t; - } -} - -template -inline char const * type() -{ - using leaf_detail::check_prefix; -char const * t = -#ifdef __FUNCSIG__ - __FUNCSIG__; -#else - __PRETTY_FUNCTION__; -#endif -#if defined(__clang__) - BOOST_LEAF_ASSERT(check_prefix(t,"const char *boost::leaf::type() ")==t+32); - return t+32; -#elif defined(__GNUC__) - BOOST_LEAF_ASSERT(check_prefix(t,"const char* boost::leaf::type() ")==t+32); - return t+32; -#else - char const * clang_style = check_prefix(t,"const char *boost::leaf::type() "); - if( clang_style!=t ) - return clang_style; - char const * gcc_style = check_prefix(t,"const char* boost::leaf::type() "); - if( gcc_style!=t ) - return gcc_style; -#endif - return t; -} - namespace leaf_detail { template @@ -86,14 +50,21 @@ namespace leaf_detail //////////////////////////////////////// - template ::value, bool ValuePrintable=has_printable_member_value::value, bool IsException=std::is_base_of::value, bool IsEnum=std::is_enum::value> + template < + class Wrapper, + bool WrapperPrintable = is_printable::value, + bool ValuePrintable = has_printable_member_value::value, + bool IsException = std::is_base_of::value, + bool IsEnum = std::is_enum::value> struct diagnostic; template struct diagnostic { static constexpr bool is_invisible = false; - static void print( std::ostream & os, Wrapper const & x ) + + template + static void print( std::basic_ostream & os, Wrapper const & x ) { os << x; } @@ -103,7 +74,9 @@ namespace leaf_detail struct diagnostic { static constexpr bool is_invisible = false; - static void print( std::ostream & os, Wrapper const & x ) + + template + static void print( std::basic_ostream & os, Wrapper const & x ) { os << type() << ": " << x.value; } @@ -113,7 +86,9 @@ namespace leaf_detail struct diagnostic { static constexpr bool is_invisible = false; - static void print( std::ostream & os, Wrapper const & ex ) + + template + static void print( std::basic_ostream & os, Wrapper const & ex ) { os << type() << ": std::exception::what(): " << ex.what(); } @@ -123,7 +98,9 @@ namespace leaf_detail struct diagnostic { static constexpr bool is_invisible = false; - static void print( std::ostream & os, Wrapper const & ) + + template + static void print( std::basic_ostream & os, Wrapper const & ) { os << type() << ": {Non-Printable}"; } @@ -133,22 +110,24 @@ namespace leaf_detail struct diagnostic { static constexpr bool is_invisible = false; - static void print( std::ostream & os, Wrapper const & w ) + + template + static void print( std::basic_ostream & os, Wrapper const & w ) { os << type() << ": " << static_cast::type>(w); } }; -#ifndef BOOST_LEAF_NO_EXCEPTIONS template <> struct diagnostic { static constexpr bool is_invisible = true; - BOOST_LEAF_CONSTEXPR static void print( std::ostream &, std::exception_ptr const & ) + + template + BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream &, std::exception_ptr const & ) { } }; -#endif } } } diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index f9f7e58..021cebd 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -16,18 +16,24 @@ # endif /// #endif /// +#include +#include #include -#include -#include #include #include -#include +#include #if BOOST_LEAF_DIAGNOSTICS +# include +# include # include # include #endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR +# include +#endif + #define BOOST_LEAF_TOKEN_PASTE(x, y) x ## y #define BOOST_LEAF_TOKEN_PASTE2(x, y) BOOST_LEAF_TOKEN_PASTE(x, y) #define BOOST_LEAF_TMP BOOST_LEAF_TOKEN_PASTE2(boost_leaf_tmp_, __LINE__) @@ -173,7 +179,9 @@ namespace leaf_detail struct diagnostic { static constexpr bool is_invisible = true; - BOOST_LEAF_CONSTEXPR static void print(std::ostream &, e_unexpected_count const &) noexcept { } + + template + BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream &, e_unexpected_count const &) noexcept { } }; class BOOST_LEAF_SYMBOL_VISIBLE e_unexpected_info @@ -210,7 +218,9 @@ namespace leaf_detail struct diagnostic { static constexpr bool is_invisible = true; - BOOST_LEAF_CONSTEXPR static void print(std::ostream &, e_unexpected_info const &) noexcept { } + + template + BOOST_LEAF_CONSTEXPR static void print( std::basic_ostream &, e_unexpected_info const &) noexcept { } }; template @@ -231,7 +241,7 @@ namespace leaf_detail namespace boost { namespace leaf { -struct e_source_location +struct BOOST_LEAF_SYMBOL_VISIBLE e_source_location { char const * file; int line; @@ -304,6 +314,7 @@ namespace leaf_detail template void print( std::basic_ostream & os, int key_to_print ) const { +#if BOOST_LEAF_DIAGNOSTICS if( !diagnostic::is_invisible ) if( int k = this->key() ) { @@ -317,6 +328,7 @@ namespace leaf_detail diagnostic::print(os, value(k)); (os << '\n').flush(); } +#endif } using impl::put; @@ -495,6 +507,7 @@ namespace leaf_detail //////////////////////////////////////// +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR namespace leaf_detail { class leaf_category final: public std::error_category @@ -544,6 +557,7 @@ inline bool is_error_id( std::error_code const & ec ) noexcept BOOST_LEAF_ASSERT(!res || !ec.value() || ((ec.value()&3)==1)); return res; } +#endif //////////////////////////////////////// @@ -571,6 +585,7 @@ public: { } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR error_id( std::error_code const & ec ) noexcept: value_(leaf_detail::import_error_code(ec)) { @@ -583,6 +598,12 @@ public: { } + std::error_code to_error_code() const noexcept + { + return std::error_code(value_, leaf_detail::get_error_category<>::cat); + } +#endif + BOOST_LEAF_CONSTEXPR error_id load() const noexcept { return *this; @@ -599,11 +620,6 @@ public: return *this; } - std::error_code to_error_code() const noexcept - { - return std::error_code(value_, leaf_detail::get_error_category<>::cat); - } - BOOST_LEAF_CONSTEXPR int value() const noexcept { if( int v = value_ ) @@ -692,7 +708,7 @@ public: virtual void deactivate() noexcept = 0; virtual void propagate() noexcept = 0; virtual bool is_active() const noexcept = 0; - virtual void print( std::ostream & ) const = 0; + inline virtual void print( std::ostream & ) const { }; error_id captured_id_; }; diff --git a/include/boost/leaf/exception.hpp b/include/boost/leaf/exception.hpp index 621d60e..10bef75 100644 --- a/include/boost/leaf/exception.hpp +++ b/include/boost/leaf/exception.hpp @@ -166,6 +166,66 @@ inline leaf_detail::exception exception() noexcept return leaf_detail::exception(leaf::new_error()); } +//////////////////////////////////////// + +#ifndef BOOST_LEAF_NO_EXCEPTIONS + +template +class result; + +namespace leaf_detail +{ + inline error_id catch_exceptions_helper( std::exception const & ex, leaf_detail_mp11::mp_list<> ) + { + return leaf::new_error(std::current_exception()); + } + + template + inline error_id catch_exceptions_helper( std::exception const & ex, leaf_detail_mp11::mp_list ) + { + if( Ex1 const * p = dynamic_cast(&ex) ) + return catch_exceptions_helper(ex, leaf_detail_mp11::mp_list{ }).load(*p); + else + return catch_exceptions_helper(ex, leaf_detail_mp11::mp_list{ }); + } + + template + struct deduce_exception_to_result_return_type_impl + { + using type = result; + }; + + template + struct deduce_exception_to_result_return_type_impl> + { + using type = result; + }; + + template + using deduce_exception_to_result_return_type = typename deduce_exception_to_result_return_type_impl::type; +} + +template +inline +leaf_detail::deduce_exception_to_result_return_type> +exception_to_result( F && f ) noexcept +{ + try + { + return std::forward(f)(); + } + catch( std::exception const & ex ) + { + return leaf_detail::catch_exceptions_helper(ex, leaf_detail_mp11::mp_list()); + } + catch(...) + { + return leaf::new_error(std::current_exception()); + } +} + +#endif + } } #if defined(_MSC_VER) && !defined(BOOST_LEAF_ENABLE_WARNINGS) /// diff --git a/include/boost/leaf/handle_errors.hpp b/include/boost/leaf/handle_errors.hpp index be147d9..0886c32 100644 --- a/include/boost/leaf/handle_errors.hpp +++ b/include/boost/leaf/handle_errors.hpp @@ -25,19 +25,21 @@ namespace boost { namespace leaf { -class error_info +class BOOST_LEAF_SYMBOL_VISIBLE error_info { error_info & operator=( error_info const & ) = delete; #ifndef BOOST_LEAF_NO_EXCEPTIONS static error_id unpack_error_id( std::exception const * ex ) noexcept { +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR if( std::system_error const * se = dynamic_cast(ex) ) if( is_error_id(se->code()) ) return leaf_detail::make_error_id(se->code().value()); if( std::error_code const * ec = dynamic_cast(ex) ) if( is_error_id(*ec) ) return leaf_detail::make_error_id(ec->value()); +#endif if( error_id const * err_id = dynamic_cast(ex) ) return *err_id; return current_error(); @@ -111,7 +113,7 @@ public: #if BOOST_LEAF_DIAGNOSTICS -class diagnostic_info: public error_info +class BOOST_LEAF_SYMBOL_VISIBLE diagnostic_info: public error_info { leaf_detail::e_unexpected_count const * e_uc_; void const * tup_; @@ -169,7 +171,7 @@ namespace leaf_detail #else -class diagnostic_info: public error_info +class BOOST_LEAF_SYMBOL_VISIBLE diagnostic_info: public error_info { protected: @@ -220,7 +222,7 @@ namespace leaf_detail #if BOOST_LEAF_DIAGNOSTICS -class verbose_diagnostic_info: public error_info +class BOOST_LEAF_SYMBOL_VISIBLE verbose_diagnostic_info: public error_info { leaf_detail::e_unexpected_info const * e_ui_; void const * tup_; @@ -278,7 +280,7 @@ namespace leaf_detail #else -class verbose_diagnostic_info: public error_info +class BOOST_LEAF_SYMBOL_VISIBLE verbose_diagnostic_info: public error_info { protected: @@ -377,6 +379,7 @@ namespace leaf_detail } }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template <> struct peek_exception { @@ -406,6 +409,7 @@ namespace leaf_detail return 0; } }; +#endif template struct peek_exception diff --git a/include/boost/leaf/pred.hpp b/include/boost/leaf/pred.hpp index 6aaf8ab..7a773f4 100644 --- a/include/boost/leaf/pred.hpp +++ b/include/boost/leaf/pred.hpp @@ -60,6 +60,7 @@ namespace leaf_detail //////////////////////////////////////// +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template struct condition { @@ -80,6 +81,7 @@ BOOST_LEAF_CONSTEXPR inline bool category( std::error_code const & ec ) return &ec.category() == &std::error_code(ErrorCodeEnum{}).category(); } #endif +#endif //////////////////////////////////////// @@ -91,6 +93,7 @@ namespace leaf_detail using type = T; }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template struct match_enum_type> { @@ -102,6 +105,7 @@ namespace leaf_detail { static_assert(sizeof(Enum) == 0, "leaf::condition should be used with leaf::match_value<>, not with leaf::match<>"); }; +#endif } template , V1, V)> @@ -117,6 +121,7 @@ struct match } }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template >), V1, V)> struct match, V1, V...> { @@ -128,6 +133,7 @@ struct match, V1, V...> return leaf_detail::cmp_value_pack(e, V1, V...); } }; +#endif template , V1, V)> struct is_predicate>: std::true_type @@ -144,6 +150,7 @@ namespace leaf_detail using type = typename std::remove_reference().value)>::type; }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template struct match_value_enum_type> { @@ -155,6 +162,7 @@ namespace leaf_detail { static_assert(sizeof(Enum)==0, "leaf::condition should be used with leaf::match<>, not with leaf::match_value<>"); }; +#endif } template , V1, V)> @@ -169,6 +177,7 @@ struct match_value } }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template >), V1, V)> struct match_value, V1, V...> { @@ -180,6 +189,7 @@ struct match_value, V1, V...> return leaf_detail::cmp_value_pack(e.value, V1, V...); } }; +#endif template , V1, V)> struct is_predicate>: std::true_type diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index bc234ca..2cd64f8 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -18,6 +18,9 @@ #include #include +#ifdef BOOST_LEAF_DISABLE_CAPTURE +# include +#endif namespace boost { namespace leaf { @@ -349,6 +352,7 @@ public: #endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR result( std::error_code const & ec ) noexcept: what_(error_id(ec)) { @@ -359,6 +363,7 @@ public: what_(error_id(e)) { } +#endif #ifdef BOOST_LEAF_DISABLE_CAPTURE result( context_ptr && ) noexcept: @@ -515,6 +520,7 @@ public: { } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR result( std::error_code const & ec ) noexcept: base(ec) { @@ -525,6 +531,7 @@ public: base(e) { } +#endif result( context_ptr && ctx ) noexcept: base(std::move(ctx)) diff --git a/meson.build b/meson.build index 7fbf490..4f4feb4 100644 --- a/meson.build +++ b/meson.build @@ -14,6 +14,7 @@ option_exceptions = (get_option('cpp_eh')!='none') option_enable_unit_tests = get_option('leaf_enable_unit_tests') option_enable_examples = get_option('leaf_enable_examples') option_enable_benchmarks = get_option('leaf_enable_benchmarks') +option_embedded = get_option('leaf_embedded') if not option_enable_examples if option_boost @@ -87,6 +88,10 @@ endif defines = [ '-DBOOST_LEAF_DIAGNOSTICS=' + option_diagnostics.to_string() ] +if option_embedded + defines += '-DBOOST_LEAF_EMBEDDED' +endif + if not option_suppress_warnings defines += '-DBOOST_LEAF_ENABLE_WARNINGS' endif diff --git a/meson_options.txt b/meson_options.txt index 7d7998d..dd914f5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -2,6 +2,7 @@ option('leaf_hpp',type:'boolean',value:false,description:'Unit tests #include BOOST_LEAF_DIAGNOSTICS=0 ; variant leaf_release_diag0 : release : BOOST_LEAF_DIAGNOSTICS=0 ; +variant leaf_debug_embedded : debug : BOOST_LEAF_EMBEDDED off off ; +variant leaf_release_embedded : release : BOOST_LEAF_EMBEDDED off off ; + variant leaf_debug_leaf_hpp : debug : BOOST_LEAF_TEST_SINGLE_HEADER ; variant leaf_release_leaf_hpp : release : BOOST_LEAF_TEST_SINGLE_HEADER ; diff --git a/test/capture_result_unload_test.cpp b/test/capture_result_unload_test.cpp index 2a85fff..b168df1 100644 --- a/test/capture_result_unload_test.cpp +++ b/test/capture_result_unload_test.cpp @@ -125,7 +125,7 @@ int main() test( [] { return leaf::capture( - std::make_shared, info<2>, info<3>>>>(), + std::make_shared, info<2>, info<3>>>>(), []() -> leaf::result { return leaf::new_error(errc_a::a0, info<1>{1}, info<3>{3}); @@ -135,7 +135,7 @@ int main() test( [] { return leaf::capture( - std::make_shared, info<2>, info<3>>>>(), + std::make_shared, info<2>, info<3>>>>(), []() -> leaf::result { return leaf::new_error(errc_a::a0, info<1>{1}, info<3>{3}); diff --git a/test/context_deduction_test.cpp b/test/context_deduction_test.cpp index e2a262f..def5c4e 100644 --- a/test/context_deduction_test.cpp +++ b/test/context_deduction_test.cpp @@ -116,15 +116,19 @@ void not_called_on_purpose() test< std::tuple,info<2>,info<3>> >( expd([]( info<1> ){ }, []( info<2>, info<3> ){ }, []( info<3> ){ }) ); test< std::tuple >( expd([]( leaf::match ){ }) ); +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR test< std::tuple >( expd([]( leaf::match, cond_x::x00> ){ }) ); +#endif test< std::tuple> >( expd([]( leaf::match_value,42> ){ }) ); +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR test< std::tuple >( expd([]( leaf::match, my_error_condition::cond1> ){ }) ); #if __cplusplus >= 201703L test< std::tuple >( expd([]( leaf::match ){ }) ); test< std::tuple >( expd([]( leaf::match ){ }) ); #endif +#endif #ifndef BOOST_LEAF_NO_EXCEPTIONS test< std::tuple> >( expd([]( leaf::catch_, info<1> ){ }) ); diff --git a/test/defer_basic_test.cpp b/test/defer_basic_test.cpp index 88ff958..07e3b4a 100644 --- a/test/defer_basic_test.cpp +++ b/test/defer_basic_test.cpp @@ -52,6 +52,7 @@ int main() []( info<42> const & i42, leaf::diagnostic_info const & di ) { BOOST_TEST_EQ(i42.value, 42); +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << di; std::string s = ss.str(); std::cout << s; @@ -59,6 +60,7 @@ int main() BOOST_TEST(s.find("info<-42>")!=s.npos); #else BOOST_TEST(s.find("BOOST_LEAF_DIAGNOSTICS")!=s.npos); +#endif #endif return 1; }, diff --git a/test/diagnostic_info_test.cpp b/test/diagnostic_info_test.cpp index f8032db..4d09935 100644 --- a/test/diagnostic_info_test.cpp +++ b/test/diagnostic_info_test.cpp @@ -104,11 +104,13 @@ int main() leaf::e_errno, leaf::error_info const & unmatched ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); BOOST_TEST_NE(s.find("leaf::error_info: Error ID = "), s.npos); std::cout << s; +#endif }, []() { @@ -140,6 +142,7 @@ int main() leaf::e_errno, leaf::diagnostic_info const & unmatched ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); @@ -159,6 +162,7 @@ int main() BOOST_TEST_NE(s.find("leaf::error_info: Error ID = "), s.npos); #endif std::cout << s; +#endif }, []() { @@ -190,6 +194,7 @@ int main() leaf::e_errno, leaf::verbose_diagnostic_info const & di ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::ostringstream st; st << di; std::string s = st.str(); @@ -211,6 +216,7 @@ int main() BOOST_TEST_NE(s.find("leaf::error_info: Error ID = "), s.npos); #endif std::cout << s; +#endif }, []() { @@ -246,6 +252,7 @@ int main() leaf::e_errno, leaf::error_info const & unmatched ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); @@ -253,6 +260,7 @@ int main() BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); std::cout << s; +#endif } ); std::cout << __LINE__ << " ----\n"; @@ -280,6 +288,7 @@ int main() leaf::e_errno, leaf::diagnostic_info const & unmatched ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); @@ -303,6 +312,7 @@ int main() BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); #endif std::cout << s; +#endif } ); std::cout << __LINE__ << " ----\n"; @@ -330,6 +340,7 @@ int main() leaf::e_errno, leaf::verbose_diagnostic_info const & di ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::ostringstream st; st << di; std::string s = st.str(); @@ -355,6 +366,7 @@ int main() BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); #endif std::cout << s; +#endif } ); #endif diff --git a/test/e_LastError_test.cpp b/test/e_LastError_test.cpp index 9edfcaa..76150f2 100644 --- a/test/e_LastError_test.cpp +++ b/test/e_LastError_test.cpp @@ -31,9 +31,11 @@ namespace leaf = boost::leaf; int main() { SetLastError(ERROR_FILE_NOT_FOUND); +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << leaf::windows::e_LastError{}; BOOST_TEST(ss.str().find("The system cannot find the file specified") != std::string::npos); +#endif int r = leaf::try_handle_all( []() -> leaf::result diff --git a/test/e_errno_test.cpp b/test/e_errno_test.cpp index b868840..a2660a5 100644 --- a/test/e_errno_test.cpp +++ b/test/e_errno_test.cpp @@ -19,9 +19,11 @@ namespace leaf = boost::leaf; int main() { errno = ENOENT; +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << leaf::e_errno{}; BOOST_TEST(ss.str().find(std::strerror(ENOENT)) != std::string::npos); +#endif int r = leaf::try_handle_all( []() -> leaf::result diff --git a/test/error_code_test.cpp b/test/error_code_test.cpp index f9ae8b3..48544f8 100644 --- a/test/error_code_test.cpp +++ b/test/error_code_test.cpp @@ -3,6 +3,19 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#include +#ifdef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR + +#include + +int main() +{ + std::cout << "Unit test not applicable." << std::endl; + return 0; +} + +#else + #ifdef BOOST_LEAF_TEST_SINGLE_HEADER # include "leaf.hpp" #else @@ -600,3 +613,5 @@ int main() test_void>(); return boost::report_errors(); } + +#endif diff --git a/test/exception_to_result_test.cpp b/test/exception_to_result_test.cpp index 7eadbf6..d6b7508 100644 --- a/test/exception_to_result_test.cpp +++ b/test/exception_to_result_test.cpp @@ -19,7 +19,7 @@ int main() #ifdef BOOST_LEAF_TEST_SINGLE_HEADER # include "leaf.hpp" #else -# include +# include # include # include #endif diff --git a/test/handle_all_other_result_test.cpp b/test/handle_all_other_result_test.cpp index f0838d3..bcfc255 100644 --- a/test/handle_all_other_result_test.cpp +++ b/test/handle_all_other_result_test.cpp @@ -3,6 +3,19 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#include +#ifdef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR + +#include + +int main() +{ + std::cout << "Unit test not applicable." << std::endl; + return 0; +} + +#else + #ifdef BOOST_LEAF_TEST_SINGLE_HEADER # include "leaf.hpp" #else @@ -82,3 +95,5 @@ int main() test const>(); return boost::report_errors(); } + +#endif diff --git a/test/handle_all_test.cpp b/test/handle_all_test.cpp index 4d6cc88..f7d330e 100644 --- a/test/handle_all_test.cpp +++ b/test/handle_all_test.cpp @@ -28,7 +28,9 @@ enum class my_error_code struct e_my_error_code { my_error_code value; }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR struct e_std_error_code { std::error_code value; }; +#endif template leaf::result f( my_error_code ec ) @@ -39,6 +41,7 @@ leaf::result f( my_error_code ec ) return leaf::new_error(ec, e_my_error_code{ec}, info<1>{1}, info<2>{2}, info<3>{3}); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template leaf::result f_errc( Errc ec ) { @@ -50,6 +53,7 @@ leaf::result f_errc_wrapped( Errc ec ) { return leaf::new_error(e_std_error_code{make_error_code(ec)}, info<1>{1}, info<2>{2}, info<3>{3}); } +#endif struct move_only { @@ -105,6 +109,7 @@ int main() BOOST_TEST_EQ(c, 1); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_all (failure), match cond_x (single enum value) { int c=0; @@ -135,7 +140,9 @@ int main() } ); BOOST_TEST_EQ(c, 2); } +#endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_all (failure), match cond_x (wrapped std::error_code) { int c=0; @@ -166,6 +173,7 @@ int main() } ); BOOST_TEST_EQ(c, 2); } +#endif // void, try_handle_all (failure), match enum (single enum value) { @@ -330,6 +338,7 @@ int main() BOOST_TEST_EQ(r, 1); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // int, try_handle_all (failure), match cond_x (single enum value) { int r = leaf::try_handle_all( @@ -355,7 +364,9 @@ int main() } ); BOOST_TEST_EQ(r, 2); } +#endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // int, try_handle_all (failure), match cond_x (wrapped std::error_code) { int r = leaf::try_handle_all( @@ -381,6 +392,7 @@ int main() } ); BOOST_TEST_EQ(r, 2); } +#endif // int, try_handle_all (failure), match enum (single enum value) { @@ -525,6 +537,7 @@ int main() BOOST_TEST_EQ(r.value, 1); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // move_only, try_handle_all (failure), match cond_x (single enum value) { move_only r = leaf::try_handle_all( @@ -550,7 +563,9 @@ int main() } ); BOOST_TEST_EQ(r.value, 2); } +#endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // move_only, try_handle_all (failure), match cond_x (wrapped std::error_code) { move_only r = leaf::try_handle_all( @@ -576,6 +591,7 @@ int main() } ); BOOST_TEST_EQ(r.value, 2); } +#endif // move_only, try_handle_all (failure), match enum (single enum value) { diff --git a/test/handle_some_other_result_test.cpp b/test/handle_some_other_result_test.cpp index 012576c..41a4412 100644 --- a/test/handle_some_other_result_test.cpp +++ b/test/handle_some_other_result_test.cpp @@ -3,6 +3,19 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#include +#ifdef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR + +#include + +int main() +{ + std::cout << "Unit test not applicable." << std::endl; + return 0; +} + +#else + #ifdef BOOST_LEAF_TEST_SINGLE_HEADER # include "leaf.hpp" #else @@ -79,3 +92,5 @@ int main() test const>(); return boost::report_errors(); } + +#endif diff --git a/test/handle_some_test.cpp b/test/handle_some_test.cpp index 97ce6b1..9de807a 100644 --- a/test/handle_some_test.cpp +++ b/test/handle_some_test.cpp @@ -28,7 +28,9 @@ enum class my_error_code struct e_my_error_code { my_error_code value; }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR struct e_std_error_code { std::error_code value; }; +#endif template leaf::result f( my_error_code ec ) @@ -39,6 +41,7 @@ leaf::result f( my_error_code ec ) return leaf::new_error(ec, e_my_error_code{ec}, info<1>{1}, info<2>{2}, info<3>{3}); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR template leaf::result f_errc( Errc ec ) { @@ -50,6 +53,7 @@ leaf::result f_errc_wrapped( Errc ec ) { return leaf::new_error(e_std_error_code{make_error_code(ec)}, info<1>{1}, info<2>{2}, info<3>{3}); } +#endif int main() { @@ -95,6 +99,7 @@ int main() BOOST_TEST(r); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_some (failure, matched), match cond_x (single enum value) { int c=0; @@ -116,7 +121,9 @@ int main() BOOST_TEST_EQ(c, 1); BOOST_TEST(r); } +#endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_some (failure, matched), match cond_x (wrapped std::error_code) { int c=0; @@ -138,6 +145,7 @@ int main() BOOST_TEST_EQ(c, 1); BOOST_TEST(r); } +#endif // void, try_handle_some (failure, matched), match enum (single enum value) { @@ -285,6 +293,7 @@ int main() BOOST_TEST_EQ(c, 2); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially not matched), match cond_x (single enum value) { int c=0; @@ -322,7 +331,9 @@ int main() } ); BOOST_TEST_EQ(c, 2); } +#endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially not matched), match cond_x (wrapped std::error_code) { int c=0; @@ -360,6 +371,7 @@ int main() } ); BOOST_TEST_EQ(c, 2); } +#endif // void, try_handle_some (failure, initially not matched), match enum (single enum value) { @@ -551,6 +563,7 @@ int main() BOOST_TEST_EQ(c, 1); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially matched), match cond_x (single enum value) { int c=0; @@ -588,7 +601,9 @@ int main() } ); BOOST_TEST_EQ(c, 1); } +#endif +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially matched), match cond_x (wrapped std::error_code) { int c=0; @@ -626,6 +641,8 @@ int main() } ); BOOST_TEST_EQ(c, 1); } +#endif + // void, try_handle_some (failure, initially matched), match enum (single enum value) { int c=0; @@ -814,6 +831,7 @@ int main() BOOST_TEST_EQ(*r, 1); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // int, try_handle_some (failure, matched), match cond_x (single enum value) { leaf::result r = leaf::try_handle_some( @@ -836,6 +854,7 @@ int main() BOOST_TEST(r); BOOST_TEST_EQ(*r, 2); } +#endif // int, try_handle_some (failure, matched), match enum (single enum value) { @@ -961,6 +980,7 @@ int main() BOOST_TEST_EQ(r, 2); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR // int, try_handle_some (failure, initially not matched), match cond_x (single enum value) { int r = leaf::try_handle_all( @@ -992,6 +1012,7 @@ int main() } ); BOOST_TEST_EQ(r, 2); } +#endif // int, try_handle_some (failure, initially not matched), match enum (single enum value) { diff --git a/test/match_member_test.cpp b/test/match_member_test.cpp index f1607a3..db32b32 100644 --- a/test/match_member_test.cpp +++ b/test/match_member_test.cpp @@ -33,7 +33,9 @@ enum class my_error { e1=1, e2, e3 }; struct e_my_error { my_error value; }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR struct e_error_code { std::error_code value; }; +#endif struct my_exception: std::exception { @@ -63,6 +65,7 @@ int main() BOOST_TEST(( test>(e) )); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR { e_error_code e = { errc_a::a0 }; @@ -70,6 +73,7 @@ int main() BOOST_TEST(( !test>(e) )); BOOST_TEST(( test>(e) )); } +#endif { int r = leaf::try_handle_all( diff --git a/test/match_test.cpp b/test/match_test.cpp index cf93104..be91061 100644 --- a/test/match_test.cpp +++ b/test/match_test.cpp @@ -80,6 +80,7 @@ int main() BOOST_TEST(( !test>>(e) )); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR { std::error_code e = errc_a::a0; @@ -102,6 +103,7 @@ int main() BOOST_TEST(( !test>>(e) )); #endif } +#endif #if __cplusplus >= 201703L { diff --git a/test/match_value_test.cpp b/test/match_value_test.cpp index 8ad212c..1a8eeff 100644 --- a/test/match_value_test.cpp +++ b/test/match_value_test.cpp @@ -21,7 +21,9 @@ enum class my_error { e1=1, e2, e3 }; struct e_my_error { my_error value; }; +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR struct e_error_code { std::error_code value; }; +#endif struct my_exception: std::exception { @@ -51,6 +53,7 @@ int main() BOOST_TEST(( test>(e) )); } +#ifndef BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR { e_error_code e = { errc_a::a0 }; @@ -64,6 +67,7 @@ int main() BOOST_TEST(( test>(e) )); #endif } +#endif { int r = leaf::try_handle_all( diff --git a/test/preload_basic_test.cpp b/test/preload_basic_test.cpp index f979d48..d4b9966 100644 --- a/test/preload_basic_test.cpp +++ b/test/preload_basic_test.cpp @@ -39,6 +39,7 @@ void test( G && g ) []( info<42> const & i42, leaf::diagnostic_info const & di ) { BOOST_TEST_EQ(i42.value, 42); +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << di; std::string s = ss.str(); std::cout << s; @@ -46,6 +47,7 @@ void test( G && g ) BOOST_TEST(s.find("info<-42>")!=s.npos); #else BOOST_TEST(s.find("BOOST_LEAF_DIAGNOSTICS")!=s.npos); +#endif #endif return 1; }, diff --git a/test/print_test.cpp b/test/print_test.cpp index 09560d8..422af09 100644 --- a/test/print_test.cpp +++ b/test/print_test.cpp @@ -3,6 +3,19 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#include +#if BOOST_LEAF_DIAGNOSTICS==0 + +#include + +int main() +{ + std::cout << "Unit test not applicable." << std::endl; + return 0; +} + +#else + #ifdef BOOST_LEAF_TEST_SINGLE_HEADER # include "leaf.hpp" #else @@ -108,3 +121,5 @@ int main() BOOST_TEST(check(my_exception{}, "std::exception::what(): my_exception_what")); return boost::report_errors(); } + +#endif diff --git a/test/result_state_test.cpp b/test/result_state_test.cpp index f7f542b..daf98c6 100644 --- a/test/result_state_test.cpp +++ b/test/result_state_test.cpp @@ -595,17 +595,21 @@ int main() } BOOST_TEST_EQ(val::count, 0); +#ifndef BOOST_LEAF_DISABLE_STD_STRING { // Initialization forwarding constructor leaf::result r = "hello"; BOOST_TEST(r); BOOST_TEST_EQ(r.value(), "hello"); } +#endif +#ifndef BOOST_LEAF_DISABLE_STD_STRING { // Initialization forwarding constructor leaf::result r; r = "hello"; BOOST_TEST(r); BOOST_TEST_EQ(r.value(), "hello"); } +#endif return boost::report_errors(); } diff --git a/test/try_catch_system_error_test.cpp b/test/try_catch_system_error_test.cpp index d59bc9c..e1db70a 100644 --- a/test/try_catch_system_error_test.cpp +++ b/test/try_catch_system_error_test.cpp @@ -4,7 +4,7 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include -#ifdef BOOST_LEAF_NO_EXCEPTIONS +#if defined(BOOST_LEAF_NO_EXCEPTIONS) || defined(BOOST_LEAF_DISABLE_STD_SYSTEM_ERROR) #include diff --git a/test/visibility_test.cpp b/test/visibility_test.cpp index 463d00c..c5a1b06 100644 --- a/test/visibility_test.cpp +++ b/test/visibility_test.cpp @@ -35,13 +35,17 @@ main() BOOST_TEST_EQ(x2.value, 2); if( BOOST_LEAF_DIAGNOSTICS ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << info; BOOST_TEST_NE(ss.str().find("1 attempt to communicate an unexpected error object"), std::string::npos); +#endif } if( BOOST_LEAF_DIAGNOSTICS ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << vinfo; BOOST_TEST_NE(ss.str().find("Test my_info<3>::value = 3"), std::string::npos); +#endif } return 1; }, @@ -66,13 +70,17 @@ main() BOOST_TEST_EQ(x2.value, 2); if( BOOST_LEAF_DIAGNOSTICS ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << info; BOOST_TEST_NE(ss.str().find("1 attempt to communicate an unexpected error object"), std::string::npos); +#endif } if( BOOST_LEAF_DIAGNOSTICS ) { +#ifndef BOOST_LEAF_DISABLE_STD_STRING std::stringstream ss; ss << vinfo; BOOST_TEST_NE(ss.str().find("Test my_info<3>::value = 3"), std::string::npos); +#endif } return 1; },