diff --git a/benchmark/benchmark.md b/benchmark/benchmark.md index 60de56e..c4aa561 100644 --- a/benchmark/benchmark.md +++ b/benchmark/benchmark.md @@ -330,7 +330,7 @@ To build both versions of the benchmark program, the compilers are invoked using In addition, the LEAF version is compiled with: -* `-DBOOST_LEAF_DIAGNOSTICS=0`: Disable diagnostic information for error objects not recognized by the program. This is a debugging feature, see [Configuration Macros](https://boostorg.github.io/leaf/#configuration). +* `-DBOOST_LEAF_CFG_DIAGNOSTICS=0`: Disable diagnostic information for error objects not recognized by the program. This is a debugging feature, see [Configuration Macros](https://boostorg.github.io/leaf/#configuration). ## Results diff --git a/benchmark/deep_stack_leaf.cpp b/benchmark/deep_stack_leaf.cpp index d955a5a..e270f4c 100644 --- a/benchmark/deep_stack_leaf.cpp +++ b/benchmark/deep_stack_leaf.cpp @@ -11,7 +11,7 @@ # error Please disable exception handling. #endif -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS # error Please disable diagnostics. #endif diff --git a/doc/leaf.adoc b/doc/leaf.adoc index a9a5e01..878c648 100644 --- a/doc/leaf.adoc +++ b/doc/leaf.adoc @@ -3717,7 +3717,7 @@ The additional information is limited to the type name of the first such error o [NOTE] -- -The behavior of `diagnostic_info` (and <>) is affected by the value of the macro `BOOST_LEAF_DIAGNOSTICS`: +The behavior of `diagnostic_info` (and <>) is affected by the value of the macro `BOOST_LEAF_CFG_DIAGNOSTICS`: * If it is 1 (the default), LEAF produces `diagnostic_info` but only if an active error handling context on the call stack takes an argument of type `diagnostic_info`; * If it is 0, the `diagnostic_info` functionality is stubbed out even for error handling contexts that take an argument of type `diagnostic_info`. This could shave a few cycles off the error path in some programs (but it is probably not worth it). @@ -4623,7 +4623,7 @@ The additional information includes the types and the values of all such error o [NOTE] -- -The behavior of `verbose_diagnostic_info` (and <>) is affected by the value of the macro `BOOST_LEAF_DIAGNOSTICS`: +The behavior of `verbose_diagnostic_info` (and <>) is affected by the value of the macro `BOOST_LEAF_CFG_DIAGNOSTICS`: * If it is 1 (the default), LEAF produces `verbose_diagnostic_info` but only if an active error handling context on the call stack takes an argument of type `verbose_diagnostic_info`; * If it is 0, the `verbose_diagnostic_info` functionality is stubbed out even for error handling contexts that take an argument of type `verbose_diagnostic_info`. This could save some cycles on the error path in some programs (but is probably not worth it). @@ -5932,9 +5932,10 @@ Assuming the current working directory is `/libs/leaf`: The following configuration macros are recognized: -* `BOOST_LEAF_DIAGNOSTICS`: Defining this macro as `0` stubs out both <> and <> (if the macro is left undefined, LEAF defines it as `1`). -* `BOOST_LEAF_USE_STD_SYSTEM_ERROR`: Defining this macro as `0` disables the `std::error_code` / `std::error_condition` integration. In this case LEAF does not `#include `, which may be too heavy for embedded platforms (if the macro is left undefined, LEAF defines it as `1`). -* `BOOST_LEAF_USE_STD_STRING`: Defining this macro as `0` disables all use of `std::string` (this requires `BOOST_LEAF_DIAGNOSTICS=0` as well). In this case LEAF does not `#include ` which may be too heavy for embedded platforms (if the macro is left undefined, LEAF defines it as `1`). +* `BOOST_LEAF_CFG_DIAGNOSTICS`: Defining this macro as `0` stubs out both <> and <> (if the macro is left undefined, LEAF defines it as `1`). +* `BOOST_LEAF_CFG_STD_SYSTEM_ERROR`: Defining this macro as `0` disables the `std::error_code` / `std::error_condition` integration. In this case LEAF does not `#include `, which may be too heavy for embedded platforms (if the macro is left undefined, LEAF defines it as `1`). +* `BOOST_LEAF_CFG_STD_STRING`: Defining this macro as `0` disables all use of `std::string` (this requires `BOOST_LEAF_CFG_DIAGNOSTICS=0` as well). In this case LEAF does not `#include ` which may be too heavy for embedded platforms (if the macro is left undefined, LEAF defines it as `1`). +* `BOOST_LEAF_CFG_CAPTURE`: Defining this macro as `0` disables the ability of `leaf::result` to transport errors between threads. In this case LEAF does not `#include `, which may be too heavy for embedded platforms (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 automatically based on the compiler configuration (e.g. `-fno-exceptions`). * `BOOST_LEAF_NO_THREADS`: Disables all thread safety in LEAF. @@ -5944,20 +5945,20 @@ Defining `BOOST_LEAF_EMBEDDED` is equivalent to the following: [source,c++] ---- -#ifndef BOOST_LEAF_NO_EXCEPTIONS -# define BOOST_LEAF_NO_EXCEPTIONS +#ifndef BOOST_LEAF_CFG_DIAGNOSTICS +# define BOOST_LEAF_CFG_DIAGNOSTICS 0 #endif -#ifndef BOOST_LEAF_DIAGNOSTICS -# define BOOST_LEAF_DIAGNOSTICS 0 +#ifndef BOOST_LEAF_CFG_STD_SYSTEM_ERROR +# define BOOST_LEAF_CFG_STD_SYSTEM_ERROR 0 #endif -#ifndef BOOST_LEAF_USE_STD_SYSTEM_ERROR -# define BOOST_LEAF_USE_STD_SYSTEM_ERROR 0 +#ifndef BOOST_LEAF_CFG_STD_STRING +# define BOOST_LEAF_CFG_STD_STRING 0 #endif -#ifndef BOOST_LEAF_USE_STD_STRING -# define BOOST_LEAF_USE_STD_STRING 0 +#ifndef BOOST_LEAF_CFG_CAPTURE +# define BOOST_LEAF_CFG_CAPTURE 0 #endif ---- @@ -5983,9 +5984,11 @@ TIP: For efficiency, `read_void_ptr` and `write_void_ptr` should be defined `inl Under `BOOST_LEAF_TLS_ARRAY` (which includes `BOOST_LEAF_TLS_FREERTOS`): * Each error type is assigned a unique index in the TLS pointer array. By default, assigned TLS indices start from `0`; this can be changed by defining `BOOST_LEAF_TLS_ARRAY_START_INDEX`. -* If `BOOST_LEAF_TLS_ARRAY_SIZE` is defined, LEAF will use it to `BOOST_LEAF_ASSERT` that TLS indices are within bounds (which is of course deactivated under `NDEBUG`). +* If `BOOST_LEAF_TLS_ARRAY_SIZE` is defined, it is used to `BOOST_LEAF_ASSERT` that TLS indices are within bounds (which is of course deactivated under `NDEBUG`). * Under `BOOST_LEAF_TLS_FREERTOS`, `BOOST_LEAF_TLS_ARRAY_SIZE` defaults to https://www.freertos.org/a00110.html#configNUM_THREAD_LOCAL_STORAGE_POINTERS[`configNUM_THREAD_LOCAL_STORAGE_POINTERS`]. +WARNING: On embedded platforms, beware of `read_void_ptr`/`write_void_ptr` accessing thread local pointers beyond the static size of the thread local pointer array; this will likely result in undefined behavior. + If your program does not use concurrency at all, simply define `BOOST_LEAF_NO_THREADS`, which requires no TLS support at all (but is NOT thread-safe). == Limitations diff --git a/example/print_file/print_file_eh.cpp b/example/print_file/print_file_eh.cpp index a290935..a5135fc 100644 --- a/example/print_file/print_file_eh.cpp +++ b/example/print_file/print_file_eh.cpp @@ -12,7 +12,6 @@ #include #include -#include #include namespace leaf = boost::leaf; diff --git a/example/print_file/print_file_outcome_result.cpp b/example/print_file/print_file_outcome_result.cpp index d5cde7e..de5a3b3 100644 --- a/example/print_file/print_file_outcome_result.cpp +++ b/example/print_file/print_file_outcome_result.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include namespace outcome = boost::outcome_v2; diff --git a/example/print_file/print_file_result.cpp b/example/print_file/print_file_result.cpp index 53829d3..9348570 100644 --- a/example/print_file/print_file_result.cpp +++ b/example/print_file/print_file_result.cpp @@ -12,7 +12,6 @@ #include #include -#include #include namespace leaf = boost::leaf; diff --git a/include/boost/leaf/capture.hpp b/include/boost/leaf/capture.hpp index d246e8e..332faae 100644 --- a/include/boost/leaf/capture.hpp +++ b/include/boost/leaf/capture.hpp @@ -16,9 +16,12 @@ # endif /// #endif /// +#include #include #include +#if BOOST_LEAF_CFG_CAPTURE + namespace boost { namespace leaf { namespace leaf_detail @@ -237,6 +240,8 @@ future_get( Future & fut ) } } +#endif + #if defined(_MSC_VER) && !defined(BOOST_LEAF_ENABLE_WARNINGS) /// #pragma warning(pop) /// #endif /// diff --git a/include/boost/leaf/common.hpp b/include/boost/leaf/common.hpp index ffe9c12..481e0ea 100644 --- a/include/boost/leaf/common.hpp +++ b/include/boost/leaf/common.hpp @@ -16,9 +16,11 @@ # endif /// #endif /// +#include #include + #include -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING # include #endif #include @@ -37,7 +39,7 @@ namespace boost { namespace leaf { struct BOOST_LEAF_SYMBOL_VISIBLE e_api_function { char const * value; }; -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING struct BOOST_LEAF_SYMBOL_VISIBLE e_file_name { diff --git a/include/boost/leaf/config.hpp b/include/boost/leaf/config.hpp index f2be831..f2f28a9 100644 --- a/include/boost/leaf/config.hpp +++ b/include/boost/leaf/config.hpp @@ -24,6 +24,13 @@ //////////////////////////////////////// +#ifdef BOOST_LEAF_DIAGNOSTICS +# warning BOOST_LEAF_DIAGNOSTICS has been renamed to BOOST_LEAF_CFG_DIAGNOSTICS. +# define BOOST_LEAF_CFG_DIAGNOSTICS BOOST_LEAF_DIAGNOSTICS +#endif + +//////////////////////////////////////// + #ifdef BOOST_LEAF_TLS_FREERTOS # ifndef BOOST_LEAF_EMBEDDED @@ -36,52 +43,60 @@ #ifdef BOOST_LEAF_EMBEDDED -# ifndef BOOST_LEAF_NO_EXCEPTIONS -# define BOOST_LEAF_NO_EXCEPTIONS +# ifndef BOOST_LEAF_CFG_DIAGNOSTICS +# define BOOST_LEAF_CFG_DIAGNOSTICS 0 # endif -# ifndef BOOST_LEAF_DIAGNOSTICS -# define BOOST_LEAF_DIAGNOSTICS 0 +# ifndef BOOST_LEAF_CFG_STD_SYSTEM_ERROR +# define BOOST_LEAF_CFG_STD_SYSTEM_ERROR 0 # endif -# ifndef BOOST_LEAF_USE_STD_SYSTEM_ERROR -# define BOOST_LEAF_USE_STD_SYSTEM_ERROR 0 +# ifndef BOOST_LEAF_CFG_STD_STRING +# define BOOST_LEAF_CFG_STD_STRING 0 # endif -# ifndef BOOST_LEAF_USE_STD_STRING -# define BOOST_LEAF_USE_STD_STRING 0 +# ifndef BOOST_LEAF_CFG_CAPTURE +# define BOOST_LEAF_CFG_CAPTURE 0 # endif #endif //////////////////////////////////////// -#ifndef BOOST_LEAF_DIAGNOSTICS -# define BOOST_LEAF_DIAGNOSTICS 1 +#ifndef BOOST_LEAF_CFG_DIAGNOSTICS +# define BOOST_LEAF_CFG_DIAGNOSTICS 1 #endif -#ifndef BOOST_LEAF_USE_STD_SYSTEM_ERROR -# define BOOST_LEAF_USE_STD_SYSTEM_ERROR 1 +#ifndef BOOST_LEAF_CFG_STD_SYSTEM_ERROR +# define BOOST_LEAF_CFG_STD_SYSTEM_ERROR 1 #endif -#ifndef BOOST_LEAF_USE_STD_STRING -# define BOOST_LEAF_USE_STD_STRING 1 +#ifndef BOOST_LEAF_CFG_STD_STRING +# define BOOST_LEAF_CFG_STD_STRING 1 #endif -#if BOOST_LEAF_DIAGNOSTICS!=0 && BOOST_LEAF_DIAGNOSTICS!=1 -# error BOOST_LEAF_DIAGNOSTICS must be 0 or 1. +#ifndef BOOST_LEAF_CFG_CAPTURE +# define BOOST_LEAF_CFG_CAPTURE 1 #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR!=0 && BOOST_LEAF_USE_STD_SYSTEM_ERROR!=1 -# error BOOST_LEAF_USE_STD_SYSTEM_ERROR must be 0 or 1. +#if BOOST_LEAF_CFG_DIAGNOSTICS!=0 && BOOST_LEAF_CFG_DIAGNOSTICS!=1 +# error BOOST_LEAF_CFG_DIAGNOSTICS must be 0 or 1. #endif -#if BOOST_LEAF_USE_STD_STRING!=0 && BOOST_LEAF_USE_STD_STRING!=1 -# error BOOST_LEAF_USE_STD_STRING must be 0 or 1. +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR!=0 && BOOST_LEAF_CFG_STD_SYSTEM_ERROR!=1 +# error BOOST_LEAF_CFG_STD_SYSTEM_ERROR must be 0 or 1. #endif -#if BOOST_LEAF_DIAGNOSTICS && !BOOST_LEAF_USE_STD_STRING -# error BOOST_LEAF_DIAGNOSTICS requires the use of std::string +#if BOOST_LEAF_CFG_STD_STRING!=0 && BOOST_LEAF_CFG_STD_STRING!=1 +# error BOOST_LEAF_CFG_STD_STRING must be 0 or 1. +#endif + +#if BOOST_LEAF_CFG_CAPTURE!=0 && BOOST_LEAF_CFG_CAPTURE!=1 +# error BOOST_LEAF_CFG_CAPTURE must be 0 or 1. +#endif + +#if BOOST_LEAF_CFG_DIAGNOSTICS && !BOOST_LEAF_CFG_STD_STRING +# error BOOST_LEAF_CFG_DIAGNOSTICS requires the use of std::string #endif //////////////////////////////////////// @@ -158,7 +173,7 @@ // Must remain the last #elif since some other vendors (Metrowerks, for // example) also #define _MSC_VER -# if !defined(_CPPUNWIND) +# if !_CPPUNWIND # define BOOST_LEAF_NO_EXCEPTIONS # endif # endif diff --git a/include/boost/leaf/context.hpp b/include/boost/leaf/context.hpp index 480228e..21a69db 100644 --- a/include/boost/leaf/context.hpp +++ b/include/boost/leaf/context.hpp @@ -16,7 +16,9 @@ # endif /// #endif /// +#include #include + #if !defined(BOOST_LEAF_NO_THREADS) && !defined(NDEBUG) # include #endif @@ -211,7 +213,7 @@ namespace leaf_detail //////////////////////////////////////////// -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS namespace leaf_detail { @@ -334,7 +336,7 @@ public: using namespace leaf_detail; BOOST_LEAF_ASSERT(!is_active()); tuple_for_each::value,Tup>::activate(tup_); -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS if( unexpected_requested::value ) tls::uint32_increment(); #endif @@ -353,7 +355,7 @@ public: BOOST_LEAF_ASSERT(std::this_thread::get_id() == thread_id_); thread_id_ = std::thread::id(); #endif -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS if( unexpected_requested::value ) tls::uint32_decrement(); #endif @@ -431,7 +433,7 @@ 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 +#if BOOST_LEAF_CFG_DIAGNOSTICS void print( std::ostream & os ) const final override { return Ctx::print(os); } #endif }; @@ -456,6 +458,8 @@ BOOST_LEAF_CONSTEXPR inline context_type_from_handlers make_context( H && //////////////////////////////////////////// +#if BOOST_LEAF_CFG_CAPTURE + template inline context_ptr make_shared_context() noexcept { @@ -468,6 +472,8 @@ inline context_ptr make_shared_context( H && ... ) noexcept return std::make_shared>>(); } +#endif + } } #if defined(_MSC_VER) && !defined(BOOST_LEAF_ENABLE_WARNINGS) /// diff --git a/include/boost/leaf/detail/all.hpp b/include/boost/leaf/detail/all.hpp index b75a7de..edf9049 100644 --- a/include/boost/leaf/detail/all.hpp +++ b/include/boost/leaf/detail/all.hpp @@ -3,6 +3,7 @@ /// 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 #include #include #include diff --git a/include/boost/leaf/detail/demangle.hpp b/include/boost/leaf/detail/demangle.hpp index 1a453b6..0d4c3f7 100644 --- a/include/boost/leaf/detail/demangle.hpp +++ b/include/boost/leaf/detail/demangle.hpp @@ -26,6 +26,7 @@ #endif /// #include + #include namespace boost { namespace leaf { @@ -90,7 +91,7 @@ char const * t = # endif #endif -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING #include diff --git a/include/boost/leaf/detail/function_traits.hpp b/include/boost/leaf/detail/function_traits.hpp index 6c72cfc..d5b4946 100644 --- a/include/boost/leaf/detail/function_traits.hpp +++ b/include/boost/leaf/detail/function_traits.hpp @@ -17,6 +17,7 @@ #endif /// #include + #include namespace boost { namespace leaf { diff --git a/include/boost/leaf/detail/optional.hpp b/include/boost/leaf/detail/optional.hpp index 58e5e0e..1c12fb0 100644 --- a/include/boost/leaf/detail/optional.hpp +++ b/include/boost/leaf/detail/optional.hpp @@ -17,6 +17,7 @@ #endif /// #include + #include #include diff --git a/include/boost/leaf/detail/print.hpp b/include/boost/leaf/detail/print.hpp index 92d8cca..4d92d4f 100644 --- a/include/boost/leaf/detail/print.hpp +++ b/include/boost/leaf/detail/print.hpp @@ -16,7 +16,11 @@ # endif /// #endif /// +#include #include + +#if BOOST_LEAF_CFG_DIAGNOSTICS + #include #include #include @@ -132,6 +136,8 @@ namespace leaf_detail } } +#endif + #if defined(_MSC_VER) && !defined(BOOST_LEAF_ENABLE_WARNINGS) /// #pragma warning(pop) /// #endif /// diff --git a/include/boost/leaf/error.hpp b/include/boost/leaf/error.hpp index 82b8b32..d2de1b0 100644 --- a/include/boost/leaf/error.hpp +++ b/include/boost/leaf/error.hpp @@ -16,24 +16,29 @@ # endif /// #endif /// +#include #include #include #include +#include + #include -#include #include -#if BOOST_LEAF_DIAGNOSTICS -# include -# include +#if BOOST_LEAF_CFG_DIAGNOSTICS # include +# include # include #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR # include #endif +#if BOOST_LEAF_CFG_CAPTURE +# 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__) @@ -121,7 +126,7 @@ BOOST_LEAF_NORETURN void throw_exception( T const & e ) namespace boost { namespace leaf { -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS namespace leaf_detail { @@ -267,7 +272,7 @@ namespace leaf_detail template void print( std::basic_ostream & os, int key_to_print ) const { -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS if( !diagnostic::is_invisible ) if( int k = this->key() ) { @@ -289,7 +294,7 @@ namespace leaf_detail using impl::value; }; -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS template BOOST_LEAF_CONSTEXPR inline void load_unexpected_count( int err_id ) noexcept @@ -332,7 +337,7 @@ namespace leaf_detail that_ = std::move(this_); } } -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS else { int c = tls::read_uint32(); @@ -353,7 +358,7 @@ namespace leaf_detail BOOST_LEAF_ASSERT((err_id&3)==1); if( slot * p = tls::read_ptr>() ) (void) p->put(err_id, std::forward(e)); -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS else { int c = tls::read_uint32(); @@ -456,7 +461,7 @@ namespace leaf_detail //////////////////////////////////////// -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR namespace leaf_detail { class leaf_category final: public std::error_category @@ -534,7 +539,7 @@ public: { } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR error_id( std::error_code const & ec ) noexcept: value_(leaf_detail::import_error_code(ec)) { @@ -661,7 +666,9 @@ public: error_id captured_id_; }; +#if BOOST_LEAF_CFG_CAPTURE using context_ptr = std::shared_ptr; +#endif //////////////////////////////////////////// diff --git a/include/boost/leaf/exception.hpp b/include/boost/leaf/exception.hpp index 10bef75..cf2d10a 100644 --- a/include/boost/leaf/exception.hpp +++ b/include/boost/leaf/exception.hpp @@ -16,7 +16,11 @@ # endif /// #endif /// +#include #include + +#ifndef BOOST_LEAF_NO_EXCEPTIONS + #include #define BOOST_LEAF_EXCEPTION ::boost::leaf::leaf_detail::inject_loc{__FILE__,__LINE__,__FUNCTION__}+::boost::leaf::exception @@ -228,6 +232,8 @@ exception_to_result( F && f ) noexcept } } +#endif + #if defined(_MSC_VER) && !defined(BOOST_LEAF_ENABLE_WARNINGS) /// #pragma warning(pop) /// #endif /// diff --git a/include/boost/leaf/handle_errors.hpp b/include/boost/leaf/handle_errors.hpp index 88371e9..022502e 100644 --- a/include/boost/leaf/handle_errors.hpp +++ b/include/boost/leaf/handle_errors.hpp @@ -16,13 +16,11 @@ # endif /// #endif /// +#include #include +#include #include -#ifndef BOOST_LEAF_NO_EXCEPTIONS -# include -#endif - namespace boost { namespace leaf { class BOOST_LEAF_SYMBOL_VISIBLE error_info @@ -32,7 +30,7 @@ class BOOST_LEAF_SYMBOL_VISIBLE error_info #ifndef BOOST_LEAF_NO_EXCEPTIONS static error_id unpack_error_id( std::exception const * ex ) noexcept { -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_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()); @@ -111,7 +109,7 @@ public: //////////////////////////////////////// -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS class BOOST_LEAF_SYMBOL_VISIBLE diagnostic_info: public error_info { @@ -188,7 +186,7 @@ public: friend std::basic_ostream & operator<<( std::basic_ostream & os, diagnostic_info const & x ) { os << - "leaf::diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1\n" + "leaf::diagnostic_info requires #define BOOST_LEAF_CFG_DIAGNOSTICS 1\n" "leaf::error_info: "; x.print(os); return os << '\n'; @@ -220,7 +218,7 @@ namespace leaf_detail //////////////////////////////////////// -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS class BOOST_LEAF_SYMBOL_VISIBLE verbose_diagnostic_info: public error_info { @@ -297,7 +295,7 @@ public: friend std::basic_ostream & operator<<( std::basic_ostream & os, verbose_diagnostic_info const & x ) { os << - "leaf::verbose_diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1\n" + "leaf::verbose_diagnostic_info requires #define BOOST_LEAF_CFG_DIAGNOSTICS 1\n" "leaf::error_info: "; x.print(os); return os << '\n'; @@ -379,7 +377,7 @@ namespace leaf_detail } }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template <> struct peek_exception { diff --git a/include/boost/leaf/on_error.hpp b/include/boost/leaf/on_error.hpp index 4776c4d..2155647 100644 --- a/include/boost/leaf/on_error.hpp +++ b/include/boost/leaf/on_error.hpp @@ -16,6 +16,7 @@ # endif /// #endif /// +#include #include namespace boost { namespace leaf { @@ -120,7 +121,7 @@ namespace leaf_detail if( !s_->has_value(err_id) ) s_->put(err_id, std::move(e_)); } -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS else { int c = tls::read_uint32(); @@ -155,7 +156,7 @@ namespace leaf_detail if( !s_->has_value(err_id) ) s_->put(err_id, f_()); } -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS else { int c = tls::read_uint32(); diff --git a/include/boost/leaf/pred.hpp b/include/boost/leaf/pred.hpp index f6805ca..2d2fa0a 100644 --- a/include/boost/leaf/pred.hpp +++ b/include/boost/leaf/pred.hpp @@ -16,6 +16,7 @@ # endif /// #endif /// +#include #include #if __cplusplus >= 201703L @@ -60,7 +61,7 @@ namespace leaf_detail //////////////////////////////////////// -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template struct condition { @@ -93,7 +94,7 @@ namespace leaf_detail using type = T; }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template struct match_enum_type> { @@ -121,7 +122,7 @@ struct match } }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template >), V1, V)> struct match, V1, V...> { @@ -150,7 +151,7 @@ namespace leaf_detail using type = typename std::remove_reference().value)>::type; }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template struct match_value_enum_type> { @@ -177,7 +178,7 @@ struct match_value } }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template >), V1, V)> struct match_value, V1, V...> { diff --git a/include/boost/leaf/result.hpp b/include/boost/leaf/result.hpp index 1515af2..404706f 100644 --- a/include/boost/leaf/result.hpp +++ b/include/boost/leaf/result.hpp @@ -16,11 +16,11 @@ # endif /// #endif /// +#include #include + #include -#ifdef BOOST_LEAF_DISABLE_CAPTURE -# include -#endif +#include namespace boost { namespace leaf { @@ -116,14 +116,13 @@ namespace leaf_detail { } +#if BOOST_LEAF_CFG_CAPTURE struct kind_ctx_ptr { }; explicit result_discriminant( kind_ctx_ptr ) noexcept: state_(ctx_ptr) { -#ifdef BOOST_LEAF_DISABLE_CAPTURE - std::abort(); // Attempted capture but capture support is disabled -#endif } +#endif kind_t kind() const noexcept { @@ -169,10 +168,10 @@ class result case result_discriminant::val: return result(error_id()); case result_discriminant::ctx_ptr: -#ifdef BOOST_LEAF_DISABLE_CAPTURE - BOOST_LEAF_ASSERT(false); // Possible ODR violation. -#else +#if BOOST_LEAF_CFG_CAPTURE return result(std::move(r_.ctx_)); +#else + BOOST_LEAF_ASSERT(0); // Possible ODR violation. #endif default: return result(std::move(r_.what_)); @@ -186,14 +185,14 @@ class result case result_discriminant::val: return error_id(); case result_discriminant::ctx_ptr: -#ifdef BOOST_LEAF_DISABLE_CAPTURE - BOOST_LEAF_ASSERT(false); // Possible ODR violation. +#if BOOST_LEAF_CFG_CAPTURE + { + error_id captured_id = r_.ctx_->propagate_captured_errors(); + tls::write_uint32(captured_id.value()); + return captured_id; + } #else - { - error_id captured_id = r_.ctx_->propagate_captured_errors(); - tls::write_uint32(captured_id.value()); - return captured_id; - } + BOOST_LEAF_ASSERT(0); // Possible ODR violation. #endif default: return r_.what_.get_error_id(); @@ -212,7 +211,7 @@ class result union { stored_type stored_; -#ifndef BOOST_LEAF_DISABLE_CAPTURE +#if BOOST_LEAF_CFG_CAPTURE context_ptr ctx_; #endif }; @@ -227,11 +226,11 @@ class result stored_.~stored_type(); break; case result_discriminant::ctx_ptr: -#ifdef BOOST_LEAF_DISABLE_CAPTURE - BOOST_LEAF_ASSERT(false); // Possible ODR violation. -#else +#if BOOST_LEAF_CFG_CAPTURE BOOST_LEAF_ASSERT(!ctx_ || ctx_->captured_id_); ctx_.~context_ptr(); +#else + BOOST_LEAF_ASSERT(0); // Possible ODR violation. #endif default: break; @@ -248,11 +247,11 @@ class result (void) new(&stored_) stored_type(std::move(x.stored_)); break; case result_discriminant::ctx_ptr: -#ifdef BOOST_LEAF_DISABLE_CAPTURE - BOOST_LEAF_ASSERT(false); // Possible ODR violation. -#else +#if BOOST_LEAF_CFG_CAPTURE BOOST_LEAF_ASSERT(!x.ctx_ || x.ctx_->captured_id_); (void) new(&ctx_) context_ptr(std::move(x.ctx_)); +#else + BOOST_LEAF_ASSERT(0); // Possible ODR violation. #endif default: break; @@ -269,11 +268,11 @@ class result error_id get_error_id() const noexcept { BOOST_LEAF_ASSERT(what_.kind()!=result_discriminant::val); -#ifdef BOOST_LEAF_DISABLE_CAPTURE +#if BOOST_LEAF_CFG_CAPTURE + return what_.kind()==result_discriminant::ctx_ptr ? ctx_->captured_id_ : what_.get_error_id(); +#else BOOST_LEAF_ASSERT(what_.kind()!=result_discriminant::ctx_ptr); // Possible ODR violation. return what_.get_error_id(); -#else - return what_.kind()==result_discriminant::ctx_ptr ? ctx_->captured_id_ : what_.get_error_id(); #endif } @@ -352,7 +351,7 @@ public: #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR result( std::error_code const & ec ) noexcept: what_(error_id(ec)) { @@ -365,12 +364,7 @@ public: } #endif -#ifdef BOOST_LEAF_DISABLE_CAPTURE - result( context_ptr && ) noexcept: - what_(result_discriminant::kind_ctx_ptr{}) - { - } -#else +#if BOOST_LEAF_CFG_CAPTURE result( context_ptr && ctx ) noexcept: ctx_(std::move(ctx)), what_(result_discriminant::kind_ctx_ptr{}) @@ -520,7 +514,7 @@ public: { } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR result( std::error_code const & ec ) noexcept: base(ec) { @@ -533,10 +527,12 @@ public: } #endif +#if BOOST_LEAF_CFG_CAPTURE result( context_ptr && ctx ) noexcept: base(std::move(ctx)) { } +#endif ~result() noexcept { diff --git a/meson.build b/meson.build index 470ff48..b9e4e35 100644 --- a/meson.build +++ b/meson.build @@ -86,7 +86,7 @@ if option_lua dep_lua = subproject('lua').get_variable('all') endif -defines = [ '-DBOOST_LEAF_DIAGNOSTICS=' + option_diagnostics.to_string() ] +defines = [ '-DBOOST_LEAF_CFG_DIAGNOSTICS=' + option_diagnostics.to_string() ] if option_embedded defines += '-DBOOST_LEAF_EMBEDDED' @@ -281,7 +281,7 @@ if option_enable_benchmarks dep_tl_expected = subproject('tl_expected').get_variable('headers') executable('deep_stack_tl', 'benchmark/deep_stack_other.cpp', override_options: ['cpp_std=c++17'], cpp_args: '-DBENCHMARK_WHAT=0', dependencies: [dep_tl_expected] ) - executable('deep_stack_leaf', 'benchmark/deep_stack_leaf.cpp', dependencies: [leaf], override_options: ['cpp_std=c++17'], cpp_args: '-DBOOST_LEAF_DIAGNOSTICS=0') + executable('deep_stack_leaf', 'benchmark/deep_stack_leaf.cpp', dependencies: [leaf], override_options: ['cpp_std=c++17'], cpp_args: '-DBOOST_LEAF_CFG_DIAGNOSTICS=0') if option_boost executable('deep_stack_result', 'benchmark/deep_stack_other.cpp', dependencies: [dep_boost], override_options: ['cpp_std=c++17'], cpp_args: '-DBENCHMARK_WHAT=1' ) executable('deep_stack_outcome', 'benchmark/deep_stack_other.cpp', dependencies: [dep_boost], override_options: ['cpp_std=c++17'], cpp_args: '-DBENCHMARK_WHAT=2' ) diff --git a/meson_options.txt b/meson_options.txt index dd914f5..ce8c0a3 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,7 +1,7 @@ option('leaf_hpp',type:'boolean',value:false,description:'Unit tests #include instead of individual headers') option('leaf_boost_examples',type:'boolean',value:false,description:'Builds the Boost examples and Boost Outcome benchmark') option('leaf_lua_examples',type:'boolean',value:false,description:'Enable or disable downloading of Lua and building the Lua examples') -option('leaf_diagnostics',type:'integer',value:1,description:'BOOST_LEAF_DIAGNOSTICS value') +option('leaf_diagnostics',type:'integer',value:1,description:'BOOST_LEAF_CFG_DIAGNOSTICS value') option('leaf_embedded',type:'boolean',value:false,description:'Defines BOOST_LEAF_EMBEDDED') option('leaf_suppress_warnings',type:'boolean',value:true,description:'Suppress compiler warnings (#pragma system_header)') option('leaf_enable_unit_tests',type:'boolean',value:true,description:'Enable the building of unit test programs') diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5fc9718..dc0ac2b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -5,8 +5,8 @@ import testing ; -variant leaf_debug_diag0 : debug : BOOST_LEAF_DIAGNOSTICS=0 ; -variant leaf_release_diag0 : release : BOOST_LEAF_DIAGNOSTICS=0 ; +variant leaf_debug_diag0 : debug : BOOST_LEAF_CFG_DIAGNOSTICS=0 ; +variant leaf_release_diag0 : release : BOOST_LEAF_CFG_DIAGNOSTICS=0 ; variant leaf_debug_embedded : debug : BOOST_LEAF_EMBEDDED off off ; variant leaf_release_embedded : release : BOOST_LEAF_EMBEDDED off off ; diff --git a/test/capture_exception_async_test.cpp b/test/capture_exception_async_test.cpp index f0bf3fc..bb6d870 100644 --- a/test/capture_exception_async_test.cpp +++ b/test/capture_exception_async_test.cpp @@ -5,7 +5,7 @@ #include -#if defined(BOOST_LEAF_NO_EXCEPTIONS) || defined(BOOST_LEAF_NO_THREADS) +#if defined(BOOST_LEAF_NO_EXCEPTIONS) || defined(BOOST_LEAF_NO_THREADS) || !BOOST_LEAF_CFG_CAPTURE #include diff --git a/test/capture_exception_result_async_test.cpp b/test/capture_exception_result_async_test.cpp index 47a0871..72c3790 100644 --- a/test/capture_exception_result_async_test.cpp +++ b/test/capture_exception_result_async_test.cpp @@ -5,7 +5,7 @@ #include -#if defined(BOOST_LEAF_NO_EXCEPTIONS) || defined(BOOST_LEAF_NO_THREADS) +#if defined(BOOST_LEAF_NO_EXCEPTIONS) || defined(BOOST_LEAF_NO_THREADS) || !BOOST_LEAF_CFG_CAPTURE #include diff --git a/test/capture_exception_state_test.cpp b/test/capture_exception_state_test.cpp index 43f0865..c94841e 100644 --- a/test/capture_exception_state_test.cpp +++ b/test/capture_exception_state_test.cpp @@ -5,7 +5,7 @@ #include -#ifdef BOOST_LEAF_NO_EXCEPTIONS +#ifdef BOOST_LEAF_NO_EXCEPTIONS || !BOOST_LEAF_CFG_CAPTURE #include diff --git a/test/capture_exception_unload_test.cpp b/test/capture_exception_unload_test.cpp index 160a346..e85c077 100644 --- a/test/capture_exception_unload_test.cpp +++ b/test/capture_exception_unload_test.cpp @@ -5,7 +5,7 @@ #include -#ifdef BOOST_LEAF_NO_EXCEPTIONS +#if defined(BOOST_LEAF_NO_EXCEPTIONS) || !BOOST_LEAF_CFG_CAPTURE #include diff --git a/test/capture_result_async_test.cpp b/test/capture_result_async_test.cpp index e98da75..fb6bc9d 100644 --- a/test/capture_result_async_test.cpp +++ b/test/capture_result_async_test.cpp @@ -5,7 +5,7 @@ #include -#ifdef BOOST_LEAF_NO_THREADS +#if defined(BOOST_LEAF_NO_THREADS) || !BOOST_LEAF_CFG_CAPTURE #include diff --git a/test/capture_result_state_test.cpp b/test/capture_result_state_test.cpp index b2d3136..160cda1 100644 --- a/test/capture_result_state_test.cpp +++ b/test/capture_result_state_test.cpp @@ -3,15 +3,9 @@ // 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) -#ifdef BOOST_LEAF_TEST_SINGLE_HEADER -# include "leaf.hpp" -#else -# include -# include -# include -#endif +#include -#ifdef BOOST_LEAF_DISABLE_CAPTURE +#if !BOOST_LEAF_CFG_CAPTURE #include @@ -23,6 +17,14 @@ int main() #else +#ifdef BOOST_LEAF_TEST_SINGLE_HEADER +# include "leaf.hpp" +#else +# include +# include +# include +#endif + #include "lightweight_test.hpp" namespace leaf = boost::leaf; diff --git a/test/capture_result_unload_test.cpp b/test/capture_result_unload_test.cpp index b168df1..97cfbb4 100644 --- a/test/capture_result_unload_test.cpp +++ b/test/capture_result_unload_test.cpp @@ -3,15 +3,9 @@ // 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) -#ifdef BOOST_LEAF_TEST_SINGLE_HEADER -# include "leaf.hpp" -#else -# include -# include -# include -#endif +#include -#ifdef BOOST_LEAF_DISABLE_CAPTURE +#if !BOOST_LEAF_CFG_CAPTURE #include @@ -23,6 +17,14 @@ int main() #else +#ifdef BOOST_LEAF_TEST_SINGLE_HEADER +# include "leaf.hpp" +#else +# include +# include +# include +#endif + #include "_test_ec.hpp" #include "lightweight_test.hpp" diff --git a/test/context_deduction_test.cpp b/test/context_deduction_test.cpp index e62e187..d9c5a31 100644 --- a/test/context_deduction_test.cpp +++ b/test/context_deduction_test.cpp @@ -116,13 +116,13 @@ 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 ){ }) ); -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR test< std::tuple >( expd([]( leaf::match, cond_x::x00> ){ }) ); #endif test< std::tuple> >( expd([]( leaf::match_value,42> ){ }) ); -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR test< std::tuple >( expd([]( leaf::match, my_error_condition::cond1> ){ }) ); #if __cplusplus >= 201703L test< std::tuple >( expd([]( leaf::match ){ }) ); @@ -137,7 +137,7 @@ void not_called_on_purpose() test< std::tuple,info<2>,info<3>> >( expd([]( info<1> const *, info<2> ){ }, []( info<1>, info<3> const * ){ }) ); test< std::tuple,info<2>,info<3>> >( expd([]( info<1> const, info<2> ){ }, []( info<1> const *, info<3> ){ }) ); -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS test< std::tuple,info<2>,leaf::leaf_detail::e_unexpected_count> >( expd([]( info<1>, info<2>, leaf::diagnostic_info const & ){ }, []( info<1>, info<2> ){ }) ); test< std::tuple,info<2>,leaf::leaf_detail::e_unexpected_info> >( expd([]( info<1>, info<2> ){ }, []( info<1>, leaf::verbose_diagnostic_info const &, info<2> ){ }) ); test< std::tuple,info<2>,leaf::leaf_detail::e_unexpected_count,leaf::leaf_detail::e_unexpected_info> >( expd([]( info<1>, info<2>, leaf::diagnostic_info const & ){ }, []( info<1>, leaf::verbose_diagnostic_info const &, info<2> ){ }) ); diff --git a/test/defer_basic_test.cpp b/test/defer_basic_test.cpp index 6a8a1b6..949d63c 100644 --- a/test/defer_basic_test.cpp +++ b/test/defer_basic_test.cpp @@ -52,14 +52,14 @@ int main() []( info<42> const & i42, leaf::diagnostic_info const & di ) { BOOST_TEST_EQ(i42.value, 42); -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::stringstream ss; ss << di; std::string s = ss.str(); std::cout << s; -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS BOOST_TEST(s.find("info<-42>")!=s.npos); #else - BOOST_TEST(s.find("BOOST_LEAF_DIAGNOSTICS")!=s.npos); + BOOST_TEST(s.find("BOOST_LEAF_CFG_DIAGNOSTICS")!=s.npos); #endif #endif return 1; diff --git a/test/diagnostic_info_test.cpp b/test/diagnostic_info_test.cpp index c743300..cea7fb2 100644 --- a/test/diagnostic_info_test.cpp +++ b/test/diagnostic_info_test.cpp @@ -104,7 +104,7 @@ int main() leaf::e_errno, leaf::error_info const & unmatched ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); @@ -142,11 +142,11 @@ int main() leaf::e_errno, leaf::diagnostic_info const & unmatched ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS BOOST_TEST_NE(s.find("leaf::diagnostic_info for Error ID = "), s.npos); BOOST_TEST_NE(s.find("e_source_location"), s.npos); BOOST_TEST_NE(s.find("*** printable_info_printable_payload printed printable_payload ***"), s.npos); @@ -158,7 +158,7 @@ int main() BOOST_TEST_NE(s.find("unexpected_test<1>"), s.npos); BOOST_TEST_EQ(s.find("unexpected_test<2>"), s.npos); #else - BOOST_TEST_NE(s.find("leaf::diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1"), s.npos); + BOOST_TEST_NE(s.find("leaf::diagnostic_info requires #define BOOST_LEAF_CFG_DIAGNOSTICS 1"), s.npos); BOOST_TEST_NE(s.find("leaf::error_info: Error ID = "), s.npos); #endif std::cout << s; @@ -194,11 +194,11 @@ int main() leaf::e_errno, leaf::verbose_diagnostic_info const & di ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::ostringstream st; st << di; std::string s = st.str(); -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS BOOST_TEST_NE(s.find("leaf::verbose_diagnostic_info for Error ID = "), s.npos); BOOST_TEST_NE(s.find("e_source_location"), s.npos); BOOST_TEST_NE(s.find("*** printable_info_printable_payload printed printable_payload ***"), s.npos); @@ -212,7 +212,7 @@ int main() BOOST_TEST_NE(s.find(": 1"), s.npos); BOOST_TEST_NE(s.find(": 2"), s.npos); #else - BOOST_TEST_NE(s.find("leaf::verbose_diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1"), s.npos); + BOOST_TEST_NE(s.find("leaf::verbose_diagnostic_info requires #define BOOST_LEAF_CFG_DIAGNOSTICS 1"), s.npos); BOOST_TEST_NE(s.find("leaf::error_info: Error ID = "), s.npos); #endif std::cout << s; @@ -252,7 +252,7 @@ int main() leaf::e_errno, leaf::error_info const & unmatched ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); @@ -288,11 +288,11 @@ int main() leaf::e_errno, leaf::diagnostic_info const & unmatched ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::ostringstream st; st << unmatched; std::string s = st.str(); -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS BOOST_TEST_NE(s.find("leaf::diagnostic_info for Error ID = "), s.npos); BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); @@ -306,7 +306,7 @@ int main() BOOST_TEST_NE(s.find("unexpected_test<1>"), s.npos); BOOST_TEST_EQ(s.find("unexpected_test<2>"), s.npos); #else - BOOST_TEST_NE(s.find("leaf::diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1"), s.npos); + BOOST_TEST_NE(s.find("leaf::diagnostic_info requires #define BOOST_LEAF_CFG_DIAGNOSTICS 1"), s.npos); BOOST_TEST_NE(s.find("leaf::error_info: Error ID = "), s.npos); BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); @@ -340,11 +340,11 @@ int main() leaf::e_errno, leaf::verbose_diagnostic_info const & di ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::ostringstream st; st << di; std::string s = st.str(); -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS BOOST_TEST_NE(s.find("leaf::verbose_diagnostic_info for Error ID = "), s.npos); BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); @@ -360,7 +360,7 @@ int main() BOOST_TEST_NE(s.find(": 1"), s.npos); BOOST_TEST_NE(s.find(": 2"), s.npos); #else - BOOST_TEST_NE(s.find("leaf::verbose_diagnostic_info requires #define BOOST_LEAF_DIAGNOSTICS 1"), s.npos); + BOOST_TEST_NE(s.find("leaf::verbose_diagnostic_info requires #define BOOST_LEAF_CFG_DIAGNOSTICS 1"), s.npos); BOOST_TEST_NE(s.find("leaf::error_info: Error ID = "), s.npos); BOOST_TEST_NE(s.find("Exception dynamic type: "), s.npos); BOOST_TEST_NE(s.find("std::exception::what(): my_exception"), s.npos); diff --git a/test/e_LastError_test.cpp b/test/e_LastError_test.cpp index 7d2d315..5967ee9 100644 --- a/test/e_LastError_test.cpp +++ b/test/e_LastError_test.cpp @@ -31,7 +31,7 @@ namespace leaf = boost::leaf; int main() { SetLastError(ERROR_FILE_NOT_FOUND); -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_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); diff --git a/test/e_errno_test.cpp b/test/e_errno_test.cpp index 90e2784..8473691 100644 --- a/test/e_errno_test.cpp +++ b/test/e_errno_test.cpp @@ -19,7 +19,7 @@ namespace leaf = boost::leaf; int main() { errno = ENOENT; -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::stringstream ss; ss << leaf::e_errno{}; BOOST_TEST(ss.str().find(std::strerror(ENOENT)) != std::string::npos); diff --git a/test/error_code_test.cpp b/test/error_code_test.cpp index 2f587b8..3459224 100644 --- a/test/error_code_test.cpp +++ b/test/error_code_test.cpp @@ -5,7 +5,7 @@ #include -#if !BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if !BOOST_LEAF_CFG_STD_SYSTEM_ERROR #include diff --git a/test/handle_all_other_result_test.cpp b/test/handle_all_other_result_test.cpp index 4ea4a85..604ee31 100644 --- a/test/handle_all_other_result_test.cpp +++ b/test/handle_all_other_result_test.cpp @@ -5,7 +5,7 @@ #include -#if !BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if !BOOST_LEAF_CFG_STD_SYSTEM_ERROR #include diff --git a/test/handle_all_test.cpp b/test/handle_all_test.cpp index 3117254..6346e57 100644 --- a/test/handle_all_test.cpp +++ b/test/handle_all_test.cpp @@ -28,7 +28,7 @@ enum class my_error_code struct e_my_error_code { my_error_code value; }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR struct e_std_error_code { std::error_code value; }; #endif @@ -41,7 +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}); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template leaf::result f_errc( Errc ec ) { @@ -109,7 +109,7 @@ int main() BOOST_TEST_EQ(c, 1); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_all (failure), match cond_x (single enum value) { int c=0; @@ -142,7 +142,7 @@ int main() } #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_all (failure), match cond_x (wrapped std::error_code) { int c=0; @@ -338,7 +338,7 @@ int main() BOOST_TEST_EQ(r, 1); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // int, try_handle_all (failure), match cond_x (single enum value) { int r = leaf::try_handle_all( @@ -366,7 +366,7 @@ int main() } #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // int, try_handle_all (failure), match cond_x (wrapped std::error_code) { int r = leaf::try_handle_all( @@ -537,7 +537,7 @@ int main() BOOST_TEST_EQ(r.value, 1); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // move_only, try_handle_all (failure), match cond_x (single enum value) { move_only r = leaf::try_handle_all( @@ -565,7 +565,7 @@ int main() } #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // move_only, try_handle_all (failure), match cond_x (wrapped std::error_code) { move_only r = leaf::try_handle_all( diff --git a/test/handle_some_other_result_test.cpp b/test/handle_some_other_result_test.cpp index 1c16fe9..66efb7e 100644 --- a/test/handle_some_other_result_test.cpp +++ b/test/handle_some_other_result_test.cpp @@ -5,7 +5,7 @@ #include -#if !BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if !BOOST_LEAF_CFG_STD_SYSTEM_ERROR #include diff --git a/test/handle_some_test.cpp b/test/handle_some_test.cpp index 8fcc84a..00a16cd 100644 --- a/test/handle_some_test.cpp +++ b/test/handle_some_test.cpp @@ -28,7 +28,7 @@ enum class my_error_code struct e_my_error_code { my_error_code value; }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR struct e_std_error_code { std::error_code value; }; #endif @@ -41,7 +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}); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR template leaf::result f_errc( Errc ec ) { @@ -99,7 +99,7 @@ int main() BOOST_TEST(r); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_some (failure, matched), match cond_x (single enum value) { int c=0; @@ -123,7 +123,7 @@ int main() } #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_some (failure, matched), match cond_x (wrapped std::error_code) { int c=0; @@ -293,7 +293,7 @@ int main() BOOST_TEST_EQ(c, 2); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially not matched), match cond_x (single enum value) { int c=0; @@ -333,7 +333,7 @@ int main() } #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially not matched), match cond_x (wrapped std::error_code) { int c=0; @@ -563,7 +563,7 @@ int main() BOOST_TEST_EQ(c, 1); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially matched), match cond_x (single enum value) { int c=0; @@ -603,7 +603,7 @@ int main() } #endif -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // void, try_handle_some (failure, initially matched), match cond_x (wrapped std::error_code) { int c=0; @@ -831,7 +831,7 @@ int main() BOOST_TEST_EQ(*r, 1); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // int, try_handle_some (failure, matched), match cond_x (single enum value) { leaf::result r = leaf::try_handle_some( @@ -980,7 +980,7 @@ int main() BOOST_TEST_EQ(r, 2); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR // int, try_handle_some (failure, initially not matched), match cond_x (single enum value) { int r = leaf::try_handle_all( diff --git a/test/match_member_test.cpp b/test/match_member_test.cpp index cc54505..2f28d68 100644 --- a/test/match_member_test.cpp +++ b/test/match_member_test.cpp @@ -33,7 +33,7 @@ enum class my_error { e1=1, e2, e3 }; struct e_my_error { my_error value; }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR struct e_error_code { std::error_code value; }; #endif @@ -65,7 +65,7 @@ int main() BOOST_TEST(( test>(e) )); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR { e_error_code e = { errc_a::a0 }; diff --git a/test/match_test.cpp b/test/match_test.cpp index 07421f2..a1f8631 100644 --- a/test/match_test.cpp +++ b/test/match_test.cpp @@ -80,7 +80,7 @@ int main() BOOST_TEST(( !test>>(e) )); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR { std::error_code e = errc_a::a0; diff --git a/test/match_value_test.cpp b/test/match_value_test.cpp index 0e4cbf2..4d46370 100644 --- a/test/match_value_test.cpp +++ b/test/match_value_test.cpp @@ -21,7 +21,7 @@ enum class my_error { e1=1, e2, e3 }; struct e_my_error { my_error value; }; -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR struct e_error_code { std::error_code value; }; #endif @@ -53,7 +53,7 @@ int main() BOOST_TEST(( test>(e) )); } -#if BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if BOOST_LEAF_CFG_STD_SYSTEM_ERROR { e_error_code e = { errc_a::a0 }; diff --git a/test/preload_basic_test.cpp b/test/preload_basic_test.cpp index e207e8f..6f5401d 100644 --- a/test/preload_basic_test.cpp +++ b/test/preload_basic_test.cpp @@ -39,14 +39,14 @@ void test( G && g ) []( info<42> const & i42, leaf::diagnostic_info const & di ) { BOOST_TEST_EQ(i42.value, 42); -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::stringstream ss; ss << di; std::string s = ss.str(); std::cout << s; -#if BOOST_LEAF_DIAGNOSTICS +#if BOOST_LEAF_CFG_DIAGNOSTICS BOOST_TEST(s.find("info<-42>")!=s.npos); #else - BOOST_TEST(s.find("BOOST_LEAF_DIAGNOSTICS")!=s.npos); + BOOST_TEST(s.find("BOOST_LEAF_CFG_DIAGNOSTICS")!=s.npos); #endif #endif return 1; diff --git a/test/print_test.cpp b/test/print_test.cpp index b38b104..772b194 100644 --- a/test/print_test.cpp +++ b/test/print_test.cpp @@ -5,7 +5,7 @@ #include -#if BOOST_LEAF_DIAGNOSTICS==0 +#if !BOOST_LEAF_CFG_DIAGNOSTICS #include diff --git a/test/result_state_test.cpp b/test/result_state_test.cpp index 705bc42..365f46c 100644 --- a/test/result_state_test.cpp +++ b/test/result_state_test.cpp @@ -181,7 +181,7 @@ int main() using context_type = leaf::leaf_detail::polymorphic_context_impl>; -#ifndef BOOST_LEAF_DISABLE_CAPTURE +#if BOOST_LEAF_CFG_CAPTURE { // value default -> capture -> move leaf::result r1 = leaf::capture( std::make_shared(), []{ return leaf::result(); } ); BOOST_TEST(r1); @@ -331,7 +331,7 @@ int main() BOOST_TEST_EQ(err::count, 0); BOOST_TEST_EQ(val::count, 0); -#ifndef BOOST_LEAF_DISABLE_CAPTURE +#if BOOST_LEAF_CFG_CAPTURE { // error move -> capture -> move leaf::result r1 = leaf::capture( std::make_shared(), []{ return leaf::result( leaf::new_error( e_err { } ) ); } ); BOOST_TEST(!r1); @@ -415,7 +415,7 @@ int main() r2.value(); } -#ifndef BOOST_LEAF_DISABLE_CAPTURE +#if BOOST_LEAF_CFG_CAPTURE { // void default -> capture -> move leaf::result r1 = leaf::capture( std::make_shared(), []{ return leaf::result(); } ); BOOST_TEST(r1); @@ -496,7 +496,7 @@ int main() } BOOST_TEST_EQ(err::count, 0); -#ifndef BOOST_LEAF_DISABLE_CAPTURE +#if BOOST_LEAF_CFG_CAPTURE { // void error move -> capture -> move leaf::result r1 = leaf::capture( std::make_shared(), []{ return leaf::result( leaf::new_error( e_err { } ) ); } ); BOOST_TEST(!r1); @@ -595,7 +595,7 @@ int main() } BOOST_TEST_EQ(val::count, 0); -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING { // Initialization forwarding constructor leaf::result r = "hello"; BOOST_TEST(r); @@ -603,7 +603,7 @@ int main() } #endif -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING { // Initialization forwarding constructor leaf::result r; r = "hello"; BOOST_TEST(r); diff --git a/test/tls_array_test.cpp b/test/tls_array_test.cpp index 9919c1d..aa48dbf 100644 --- a/test/tls_array_test.cpp +++ b/test/tls_array_test.cpp @@ -4,9 +4,12 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #define BOOST_LEAF_NO_EXCEPTIONS -#define BOOST_LEAF_USE_STD_SYSTEM_ERROR 0 -#define BOOST_LEAF_USE_STD_STRING 0 -#define BOOST_LEAF_DIAGNOSTICS 0 +#define BOOST_LEAF_CFG_STD_SYSTEM_ERROR 0 +#define BOOST_LEAF_CFG_STD_STRING 0 +#ifdef BOOST_LEAF_CFG_DIAGNOSTICS +# undef BOOST_LEAF_CFG_DIAGNOSTICS +#endif +#define BOOST_LEAF_CFG_DIAGNOSTICS 0 #define BOOST_LEAF_TLS_ARRAY #define BOOST_LEAF_TLS_ARRAY_SIZE 64 #define BOOST_LEAF_TLS_ARRAY_START_INDEX 10 diff --git a/test/try_catch_system_error_test.cpp b/test/try_catch_system_error_test.cpp index c2874d1..2058548 100644 --- a/test/try_catch_system_error_test.cpp +++ b/test/try_catch_system_error_test.cpp @@ -5,7 +5,7 @@ #include -#if defined(BOOST_LEAF_NO_EXCEPTIONS) || !BOOST_LEAF_USE_STD_SYSTEM_ERROR +#if defined(BOOST_LEAF_NO_EXCEPTIONS) || !BOOST_LEAF_CFG_STD_SYSTEM_ERROR #include diff --git a/test/visibility_test.cpp b/test/visibility_test.cpp index de5a407..b681300 100644 --- a/test/visibility_test.cpp +++ b/test/visibility_test.cpp @@ -32,16 +32,16 @@ int main() { BOOST_TEST_EQ(x1.value, 1); BOOST_TEST_EQ(x2.value, 2); - if( BOOST_LEAF_DIAGNOSTICS ) + if( BOOST_LEAF_CFG_DIAGNOSTICS ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_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 ) + if( BOOST_LEAF_CFG_DIAGNOSTICS ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::stringstream ss; ss << vinfo; BOOST_TEST_NE(ss.str().find("Test my_info<3>::value = 3"), std::string::npos); #endif @@ -67,16 +67,16 @@ int main() { BOOST_TEST_EQ(x1.value, 1); BOOST_TEST_EQ(x2.value, 2); - if( BOOST_LEAF_DIAGNOSTICS ) + if( BOOST_LEAF_CFG_DIAGNOSTICS ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_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 ) + if( BOOST_LEAF_CFG_DIAGNOSTICS ) { -#if BOOST_LEAF_USE_STD_STRING +#if BOOST_LEAF_CFG_STD_STRING std::stringstream ss; ss << vinfo; BOOST_TEST_NE(ss.str().find("Test my_info<3>::value = 3"), std::string::npos); #endif