diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2208684..ff166a6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -162,3 +162,4 @@ boost_test(TYPE run SOURCES result_error_construct3.cpp) boost_test(TYPE run SOURCES result_emplace.cpp) boost_test(TYPE run SOURCES result_error_construct4.cpp) boost_test(TYPE run SOURCES result_value_construct4.cpp) +boost_test(TYPE run SOURCES result_value_construct5.cpp) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 84d549c..df74b5e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -192,3 +192,4 @@ run result_error_construct3.cpp : : : $(CPP11) ; run result_emplace.cpp : : : $(CPP11) ; run result_error_construct4.cpp : : : $(CPP11) ; run result_value_construct4.cpp : : : $(CPP11) ; +run result_value_construct5.cpp : : : $(CPP11) ; diff --git a/test/result_value_construct5.cpp b/test/result_value_construct5.cpp new file mode 100644 index 0000000..ab6cd2c --- /dev/null +++ b/test/result_value_construct5.cpp @@ -0,0 +1,82 @@ +// Copyright 2023 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +using namespace boost::system; + +// Tricky mixed construction cases +// https://github.com/boostorg/system/issues/104 +// https://brevzin.github.io//c++/2023/01/18/optional-construction/ + +template void test() +{ + { + R1 r1( make_error_code( errc::invalid_argument ) ); + R2 r2( r1 ); + + BOOST_TEST( !r2.has_value() ); + } + + { + R1 r1( 0 ); + R2 r2( r1 ); + + BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), false ); + } + + { + R1 r1( 1 ); + R2 r2( r1 ); + + BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), true ); + } + + { + R1 r1( make_error_code( errc::invalid_argument ) ); + R2 r2( std::move( r1 ) ); + + BOOST_TEST( !r2.has_value() ); + } + + { + R1 r1( 0 ); + R2 r2( std::move( r1 ) ); + + BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), false ); + } + + { + R1 r1( 1 ); + R2 r2( std::move( r1 ) ); + + BOOST_TEST( r2.has_value() ) && BOOST_TEST_EQ( r2.value(), true ); + } +} + +struct X +{ +}; + +int main() +{ + test< result, result >(); + test< result const, result >(); + + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result&>)); + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result const&>)); + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result&&>)); + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result const&&>)); + + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result&>)); + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result const&>)); + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result&&>)); + BOOST_TEST_TRAIT_FALSE((std::is_constructible, result const&&>)); + + return boost::report_errors(); +}