tests: added two test cases from GitHub issues

This commit is contained in:
Andrzej Krzemienski
2018-10-29 21:47:09 +01:00
parent fae2791f45
commit 65bb040db8
3 changed files with 58 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import testing ;
{ {
test-suite optional : test-suite optional :
[ run optional_test.cpp ] [ run optional_test.cpp ]
[ run optional_test_assign.cpp ]
[ run optional_test_swap.cpp ] [ run optional_test_swap.cpp ]
[ run optional_test_conversions_from_U.cpp ] [ run optional_test_conversions_from_U.cpp ]
[ run optional_test_convert_from_T.cpp ] [ run optional_test_convert_from_T.cpp ]

View File

@ -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<int> oa, ob(1);
BOOST_TEST(!oa);
BOOST_TEST(ob);
oa = ob;
BOOST_TEST(oa);
}
int main()
{
test_assignment_to_empty();
return boost::report_errors();
}

View File

@ -1,4 +1,6 @@
// Copyright 2017 Peter Dimov // Copyright 2017 Peter Dimov
// Copyright 2017 Vinnie NotDefaultConstructible
// Copyright 2018 Andrzej Krzemienski
// //
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// //
@ -19,8 +21,8 @@ int main()
class basic_multi_buffer; 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_; basic_multi_buffer const* b_;
friend class basic_multi_buffer; friend class basic_multi_buffer;
@ -29,16 +31,36 @@ class const_buffers_type
const_buffers_type(basic_multi_buffer const& b); const_buffers_type(basic_multi_buffer const& b);
public: public:
const_buffers_type() = delete; const_buffers_type() = delete;
const_buffers_type(const_buffers_type const&) = default; const_buffers_type(const_buffers_type const&) = default;
const_buffers_type& operator=(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<const_buffers_type, int> > 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<NotDefaultConstructible> opt, opt2;
opt = opt2;
(void)opt;
}
int main() int main()
{ {
boost::optional< std::pair<const_buffers_type, int> > opt, opt2; test_beast_example();
opt = opt2; test_assign_for_non_default_constructible();
} }
#endif #endif