diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 8126239..f6912a9 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -18,6 +18,7 @@ import testing ; { test-suite optional : [ run optional_test.cpp ] + [ run optional_test_assign.cpp ] [ run optional_test_swap.cpp ] [ run optional_test_conversions_from_U.cpp ] [ run optional_test_convert_from_T.cpp ] diff --git a/test/optional_test_assign.cpp b/test/optional_test_assign.cpp new file mode 100644 index 0000000..07dfcdc --- /dev/null +++ b/test/optional_test_assign.cpp @@ -0,0 +1,30 @@ +// Copyright (C) 2018 Andrzej Krzemienski. +// +// Use, modification, and distribution is subject to 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) +// +// See http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: +// akrzemi1@gmail.com + +#include "boost/core/lightweight_test.hpp" +#include "boost/optional/optional.hpp" + +void test_assignment_to_empty() +{ + // this test used to fail on GCC 8.1.0/8.2.0/9.0.0 with -std=c++98 + boost::optional oa, ob(1); + BOOST_TEST(!oa); + BOOST_TEST(ob); + + oa = ob; + BOOST_TEST(oa); +} + +int main() +{ + test_assignment_to_empty(); + return boost::report_errors(); +} diff --git a/test/optional_test_deleted_default_ctor.cpp b/test/optional_test_deleted_default_ctor.cpp index e98b381..790753c 100644 --- a/test/optional_test_deleted_default_ctor.cpp +++ b/test/optional_test_deleted_default_ctor.cpp @@ -1,4 +1,6 @@ // Copyright 2017 Peter Dimov +// Copyright 2017 Vinnie NotDefaultConstructible +// Copyright 2018 Andrzej Krzemienski // // Distributed under the Boost Software License, Version 1.0. // @@ -19,8 +21,8 @@ int main() class basic_multi_buffer; -class const_buffers_type -{ +class const_buffers_type // a similar declaration in boost.beast had problem +{ // with boost opitonal basic_multi_buffer const* b_; friend class basic_multi_buffer; @@ -29,16 +31,36 @@ class const_buffers_type const_buffers_type(basic_multi_buffer const& b); public: - const_buffers_type() = delete; const_buffers_type(const_buffers_type const&) = default; const_buffers_type& operator=(const_buffers_type const&) = default; }; +void test_beast_example() +{ + // test if it even compiles + boost::optional< std::pair > opt, opt2; + opt = opt2; + (void)opt; +} + +struct NotDefaultConstructible // minimal class exposing the problem +{ + NotDefaultConstructible() = delete; +}; + +void test_assign_for_non_default_constructible() +{ + // test if it even compiles + boost::optional opt, opt2; + opt = opt2; + (void)opt; +} + int main() { - boost::optional< std::pair > opt, opt2; - opt = opt2; + test_beast_example(); + test_assign_for_non_default_constructible(); } #endif