From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/conversion/CMakeLists.txt | 24 ++ src/boost/libs/conversion/README.md | 16 + src/boost/libs/conversion/index.html | 35 ++ src/boost/libs/conversion/meta/libraries.json | 15 + src/boost/libs/conversion/test/Jamfile.v2 | 29 ++ src/boost/libs/conversion/test/cast_test.cpp | 82 +++++ src/boost/libs/conversion/test/implicit_cast.cpp | 38 +++ .../libs/conversion/test/implicit_cast_fail.cpp | 20 ++ .../libs/conversion/test/implicit_cast_fail2.cpp | 19 ++ .../libs/conversion/test/polymorphic_cast_test.cpp | 373 +++++++++++++++++++++ 10 files changed, 651 insertions(+) create mode 100644 src/boost/libs/conversion/CMakeLists.txt create mode 100644 src/boost/libs/conversion/README.md create mode 100644 src/boost/libs/conversion/index.html create mode 100644 src/boost/libs/conversion/meta/libraries.json create mode 100644 src/boost/libs/conversion/test/Jamfile.v2 create mode 100644 src/boost/libs/conversion/test/cast_test.cpp create mode 100644 src/boost/libs/conversion/test/implicit_cast.cpp create mode 100644 src/boost/libs/conversion/test/implicit_cast_fail.cpp create mode 100644 src/boost/libs/conversion/test/implicit_cast_fail2.cpp create mode 100644 src/boost/libs/conversion/test/polymorphic_cast_test.cpp (limited to 'src/boost/libs/conversion') diff --git a/src/boost/libs/conversion/CMakeLists.txt b/src/boost/libs/conversion/CMakeLists.txt new file mode 100644 index 00000000..b333aab0 --- /dev/null +++ b/src/boost/libs/conversion/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright 2019 Mike Dev +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt +# +# NOTE: CMake support for Boost.Conversion is currently experimental at best +# and the interface is likely to change in the future + +cmake_minimum_required( VERSION 3.5 ) +project( BoostConversion LANGUAGES CXX ) + +add_library( boost_conversion INTERFACE ) +add_library( Boost::conversion ALIAS boost_conversion ) + +target_include_directories( boost_conversion INTERFACE include ) + +target_link_libraries( boost_conversion + INTERFACE + Boost::assert + Boost::config + Boost::smart_ptr + Boost::throw_exception + Boost::type_traits + Boost::typeof +) diff --git a/src/boost/libs/conversion/README.md b/src/boost/libs/conversion/README.md new file mode 100644 index 00000000..2cd1b9d4 --- /dev/null +++ b/src/boost/libs/conversion/README.md @@ -0,0 +1,16 @@ +# [Boost.Conversion](http://boost.org/libs/conversion) +Boost.Conversion is one of the [Boost C++ Libraries](http://github.com/boostorg). This library improves program safety and clarity by performing otherwise messy conversions. + +### Test results + +@ | Build | Tests coverage | More info +----------------|-------------- | -------------- |----------- +Develop branch: | [![Build Status](https://travis-ci.org/apolukhin/conversion.svg?branch=develop)](https://travis-ci.org/apolukhin/conversion) [![Build status](https://ci.appveyor.com/api/projects/status/yep84179w535pppg/branch/develop?svg=true)](https://ci.appveyor.com/project/apolukhin/conversion/branch/develop) | [![Coverage Status](https://coveralls.io/repos/apolukhin/conversion/badge.png?branch=develop)](https://coveralls.io/r/apolukhin/conversion?branch=develop) | [details...](http://www.boost.org/development/tests/develop/developer/conversion.html) +Master branch: | [![Build Status](https://travis-ci.org/apolukhin/conversion.svg?branch=master)](https://travis-ci.org/apolukhin/conversion) [![Build status](https://ci.appveyor.com/api/projects/status/yep84179w535pppg/branch/master?svg=true)](https://ci.appveyor.com/project/apolukhin/conversion/branch/master) | [![Coverage Status](https://coveralls.io/repos/apolukhin/conversion/badge.png?branch=master)](https://coveralls.io/r/apolukhin/conversion?branch=master) | [details...](http://www.boost.org/development/tests/master/developer/conversion.html) + + +[Open Issues](https://svn.boost.org/trac/boost/query?status=!closed&component=conversion&or&status=!closed&component=lexical_cast) + +### License + +Distributed under the [Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt). diff --git a/src/boost/libs/conversion/index.html b/src/boost/libs/conversion/index.html new file mode 100644 index 00000000..0f61fb0c --- /dev/null +++ b/src/boost/libs/conversion/index.html @@ -0,0 +1,35 @@ + + + + + + +Boost.Conversion + + + +

+ Automatic redirection failed, please go to + ../../doc/html/conversion.html +

+

+ © 2014 Antony Polukhin +

+ + \ No newline at end of file diff --git a/src/boost/libs/conversion/meta/libraries.json b/src/boost/libs/conversion/meta/libraries.json new file mode 100644 index 00000000..3c7c7262 --- /dev/null +++ b/src/boost/libs/conversion/meta/libraries.json @@ -0,0 +1,15 @@ +{ + "key": "conversion", + "name": "Conversion", + "authors": [ + "Dave Abrahams", + "Kevlin Henney" + ], + "description": "Polymorphic casts.", + "category": [ + "Miscellaneous" + ], + "maintainers": [ + "Antony Polukhin " + ] +} diff --git a/src/boost/libs/conversion/test/Jamfile.v2 b/src/boost/libs/conversion/test/Jamfile.v2 new file mode 100644 index 00000000..c513ee85 --- /dev/null +++ b/src/boost/libs/conversion/test/Jamfile.v2 @@ -0,0 +1,29 @@ +# Copyright (C) 2001-2003 Douglas Gregor +# Copyright (C) 2011-2014 Antony Polukhin +# +# 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) +# + +import testing ; +import feature ; + +project + : requirements + gcc-4.7:-ftrapv + gcc-4.6:-ftrapv + clang:-ftrapv + # default to all warnings on: + all + # set warnings as errors for those compilers we know we get warning free: + gcc:-Wextra + gcc:-Wno-uninitialized + ; + +test-suite conversion + : [ run implicit_cast.cpp ] + [ compile-fail implicit_cast_fail.cpp ] + [ run cast_test.cpp ] + [ run polymorphic_cast_test.cpp ] + [ compile-fail implicit_cast_fail2.cpp ] + ; diff --git a/src/boost/libs/conversion/test/cast_test.cpp b/src/boost/libs/conversion/test/cast_test.cpp new file mode 100644 index 00000000..87473978 --- /dev/null +++ b/src/boost/libs/conversion/test/cast_test.cpp @@ -0,0 +1,82 @@ +// boost utility cast test program -----------------------------------------// + +// (C) Copyright Beman Dawes, Dave Abrahams 1999. 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) + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 28 Set 04 factored out numeric_cast<> test (Fernando Cacciola) +// 20 Jan 01 removed use of for portability to raw GCC (David Abrahams) +// 28 Jun 00 implicit_cast removed (Beman Dawes) +// 30 Aug 99 value_cast replaced by numeric_cast +// 3 Aug 99 Initial Version + +#include +#include +#include + +using namespace boost; +using std::cout; + +namespace +{ + struct Base + { + virtual char kind() { return 'B'; } + }; + + struct Base2 + { + virtual char kind2() { return '2'; } + }; + + struct Derived : public Base, Base2 + { + virtual char kind() { return 'D'; } + }; +} + + +int main( int argc, char * argv[] ) +{ +# ifdef NDEBUG + cout << "NDEBUG is defined\n"; +# else + cout << "NDEBUG is not defined\n"; +# endif + + cout << "\nBeginning tests...\n"; + +// test polymorphic_cast ---------------------------------------------------// + + // tests which should succeed + Derived derived_instance; + Base * base = &derived_instance; + Derived * derived = polymorphic_downcast( base ); // downcast + BOOST_TEST( derived->kind() == 'D' ); + + derived = polymorphic_cast( base ); // downcast, throw on error + BOOST_TEST( derived->kind() == 'D' ); + + Base2 * base2 = polymorphic_cast( base ); // crosscast + BOOST_TEST( base2->kind2() == '2' ); + + // tests which should result in errors being detected + Base base_instance; + base = &base_instance; + + if ( argc > 1 && *argv[1] == '1' ) + { derived = polymorphic_downcast( base ); } // #1 assert failure + + bool caught_exception = false; + try { derived = polymorphic_cast( base ); } + catch (const std::bad_cast&) + { cout<<"caught bad_cast\n"; caught_exception = true; } + BOOST_TEST( caught_exception ); + // the following is just so generated code can be inspected + BOOST_TEST( derived->kind() != 'B' ); + + return boost::report_errors(); +} // main diff --git a/src/boost/libs/conversion/test/implicit_cast.cpp b/src/boost/libs/conversion/test/implicit_cast.cpp new file mode 100644 index 00000000..eaca42a8 --- /dev/null +++ b/src/boost/libs/conversion/test/implicit_cast.cpp @@ -0,0 +1,38 @@ +// Copyright David Abrahams 2003. +// 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 +using boost::implicit_cast; +using boost::type; + +template +type check_return(T) { return type(); } + +struct foo +{ + foo(char const*) {} + operator long() const { return 0; } +}; + +typedef type long_type; +typedef type foo_type; + +int main() +{ + type x = check_return(boost::implicit_cast(1)); + BOOST_TEST(boost::implicit_cast(1) == 1L); + + type f = check_return(boost::implicit_cast("hello")); + type z = check_return(boost::implicit_cast(foo("hello"))); + + // warning suppression: + (void)x; + (void)f; + (void)z; + + return boost::report_errors(); +} diff --git a/src/boost/libs/conversion/test/implicit_cast_fail.cpp b/src/boost/libs/conversion/test/implicit_cast_fail.cpp new file mode 100644 index 00000000..86ccbb25 --- /dev/null +++ b/src/boost/libs/conversion/test/implicit_cast_fail.cpp @@ -0,0 +1,20 @@ +// Copyright David Abrahams 2003. +// 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 + +using boost::implicit_cast; + +struct foo +{ + explicit foo(char const*) {} +}; + +int main() +{ + foo x = implicit_cast("foobar"); + (void)x; // warning suppression. + return 0; +} diff --git a/src/boost/libs/conversion/test/implicit_cast_fail2.cpp b/src/boost/libs/conversion/test/implicit_cast_fail2.cpp new file mode 100644 index 00000000..97cc2d82 --- /dev/null +++ b/src/boost/libs/conversion/test/implicit_cast_fail2.cpp @@ -0,0 +1,19 @@ +// +// Test that implicit_cast requires a template argument +// +// Copyright 2014 Peter Dimov +// +// 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 + +int main() +{ + int x = boost::implicit_cast( 1 ); + (void)x; + + return 0; +} diff --git a/src/boost/libs/conversion/test/polymorphic_cast_test.cpp b/src/boost/libs/conversion/test/polymorphic_cast_test.cpp new file mode 100644 index 00000000..d0e527d2 --- /dev/null +++ b/src/boost/libs/conversion/test/polymorphic_cast_test.cpp @@ -0,0 +1,373 @@ +// +// Test boost::polymorphic_cast, boost::polymorphic_downcast and +// boost::polymorphic_pointer_cast, boost::polymorphic_pointer_downcast +// +// Copyright 1999 Beman Dawes +// Copyright 1999 Dave Abrahams +// Copyright 2014 Peter Dimov +// Copyright 2014 Boris Rasin, Antony Polukhin +// +// 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 +// + +#define BOOST_ENABLE_ASSERT_HANDLER +#include +#include +#include +#include +#include +#include +#include +#include + +static bool expect_assertion = false; +static int assertion_failed_count = 0; + +//assertion handler throws it to exit like assert, but to be able to catch it and stop +//usage: BOOST_TEST_THROWS( function_with_assert(), expected_assertion ); +struct expected_assertion {}; + +// BOOST_ASSERT custom handler +void boost::assertion_failed( char const * expr, char const * function, char const * file, long line ) +{ + if( expect_assertion ) + { + ++assertion_failed_count; + throw expected_assertion(); + } + else + { + BOOST_ERROR( "unexpected assertion" ); + + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): assertion '" << expr << "' failed in function '" + << function << "'" << std::endl; + } +} + +// + +struct Base : boost::intrusive_ref_counter +{ + virtual ~Base() {} + virtual std::string kind() { return "Base"; } +}; + +struct Base2 +{ + virtual ~Base2() {} + virtual std::string kind2() { return "Base2"; } +}; + +struct Derived : public Base, Base2 +{ + virtual std::string kind() { return "Derived"; } +}; + +static void test_polymorphic_cast() +{ + Base * base = new Derived; + + Derived * derived; + + try + { + derived = boost::polymorphic_cast( base ); + + BOOST_TEST( derived != 0 ); + + if( derived != 0 ) + { + BOOST_TEST_EQ( derived->kind(), "Derived" ); + } + } + catch( std::bad_cast const& ) + { + BOOST_ERROR( "boost::polymorphic_cast( base ) threw std::bad_cast" ); + } + + Base2 * base2; + + try + { + base2 = boost::polymorphic_cast( base ); // crosscast + + BOOST_TEST( base2 != 0 ); + + if( base2 != 0 ) + { + BOOST_TEST_EQ( base2->kind2(), "Base2" ); + } + } + catch( std::bad_cast const& ) + { + BOOST_ERROR( "boost::polymorphic_cast( base ) threw std::bad_cast" ); + } + + delete base; +} + +static void test_polymorphic_pointer_cast() +{ + Base * base = new Derived; + + Derived * derived; + + try + { + derived = boost::polymorphic_pointer_cast( base ); + + BOOST_TEST( derived != 0 ); + + if( derived != 0 ) + { + BOOST_TEST_EQ( derived->kind(), "Derived" ); + } + } + catch( std::bad_cast const& ) + { + BOOST_ERROR( "boost::polymorphic_pointer_cast( base ) threw std::bad_cast" ); + } + + Base2 * base2; + + try + { + base2 = boost::polymorphic_pointer_cast( base ); // crosscast + + BOOST_TEST( base2 != 0 ); + + if( base2 != 0 ) + { + BOOST_TEST_EQ( base2->kind2(), "Base2" ); + } + } + catch( std::bad_cast const& ) + { + BOOST_ERROR( "boost::polymorphic_pointer_cast( base ) threw std::bad_cast" ); + } + + boost::shared_ptr sp_base( base ); + boost::shared_ptr sp_base2; + try + { + sp_base2 = boost::polymorphic_pointer_cast( sp_base ); // crosscast + + BOOST_TEST( sp_base2 != 0 ); + + if( sp_base2 != 0 ) + { + BOOST_TEST_EQ( sp_base2->kind2(), "Base2" ); + } + } + catch( std::bad_cast const& ) + { + BOOST_ERROR( "boost::polymorphic_pointer_cast( sp_base ) threw std::bad_cast" ); + } + + // we do not `delete base;` because sahred_ptr is holding base +} + +static void test_polymorphic_downcast() +{ + Base * base = new Derived; + + Derived * derived = boost::polymorphic_downcast( base ); + + BOOST_TEST( derived != 0 ); + + if( derived != 0 ) + { + BOOST_TEST_EQ( derived->kind(), "Derived" ); + } + + // polymorphic_downcast can't do crosscasts + + delete base; +} + +static void test_polymorphic_pointer_downcast_builtin() +{ + Base * base = new Derived; + + Derived * derived = boost::polymorphic_pointer_downcast( base ); + + BOOST_TEST( derived != 0 ); + + if( derived != 0 ) + { + BOOST_TEST_EQ( derived->kind(), "Derived" ); + } + + // polymorphic_pointer_downcast can't do crosscasts + + delete base; +} + +static void test_polymorphic_pointer_downcast_boost_shared() +{ + boost::shared_ptr base (new Derived); + + boost::shared_ptr derived = boost::polymorphic_pointer_downcast( base ); + + BOOST_TEST( derived != 0 ); + + if( derived != 0 ) + { + BOOST_TEST_EQ( derived->kind(), "Derived" ); + } +} + +static void test_polymorphic_pointer_downcast_intrusive() +{ + boost::intrusive_ptr base (new Derived); + + boost::intrusive_ptr derived = boost::polymorphic_pointer_downcast( base ); + + BOOST_TEST( derived != 0 ); + + if( derived != 0 ) + { + BOOST_TEST_EQ( derived->kind(), "Derived" ); + } +} + +#ifndef BOOST_NO_CXX11_SMART_PTR + +static void test_polymorphic_pointer_downcast_std_shared() +{ + std::shared_ptr base (new Derived); + + std::shared_ptr derived = boost::polymorphic_pointer_downcast( base ); + + BOOST_TEST( derived != 0 ); + + if( derived != 0 ) + { + BOOST_TEST_EQ( derived->kind(), "Derived" ); + } +} + +#endif + +static void test_polymorphic_cast_fail() +{ + Base * base = new Base; + + BOOST_TEST_THROWS( boost::polymorphic_cast( base ), std::bad_cast ); + + delete base; +} + +static void test_polymorphic_pointer_cast_fail() +{ + Base * base = new Base; + BOOST_TEST_THROWS( boost::polymorphic_pointer_cast( base ), std::bad_cast ); + delete base; + + BOOST_TEST_THROWS( boost::polymorphic_pointer_cast( boost::shared_ptr(new Base) ), std::bad_cast ); + +#ifndef BOOST_NO_CXX11_SMART_PTR + BOOST_TEST_THROWS( boost::polymorphic_pointer_cast( std::shared_ptr(new Base) ), std::bad_cast ); +#endif + + BOOST_TEST_THROWS( boost::polymorphic_pointer_cast( boost::intrusive_ptr(new Base) ), std::bad_cast ); +} + +static void test_polymorphic_downcast_fail() +{ + Base * base = new Base; + + int old_count = assertion_failed_count; + expect_assertion = true; + + BOOST_TEST_THROWS( boost::polymorphic_downcast( base ), expected_assertion ); // should assert + + BOOST_TEST_EQ( assertion_failed_count, old_count + 1 ); + expect_assertion = false; + + delete base; +} + +static void test_polymorphic_pointer_downcast_builtin_fail() +{ + Base * base = new Base; + + int old_count = assertion_failed_count; + expect_assertion = true; + + BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast( base ), expected_assertion ); // should assert + + BOOST_TEST_EQ( assertion_failed_count, old_count + 1 ); + expect_assertion = false; + + delete base; +} + +static void test_polymorphic_pointer_downcast_boost_shared_fail() +{ + boost::shared_ptr base (new Base); + + int old_count = assertion_failed_count; + expect_assertion = true; + + BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast( base ), expected_assertion ); // should assert + + BOOST_TEST_EQ( assertion_failed_count, old_count + 1 ); + expect_assertion = false; +} + +#ifndef BOOST_NO_CXX11_SMART_PTR + +static void test_polymorphic_pointer_downcast_std_shared_fail() +{ + std::shared_ptr base (new Base); + + int old_count = assertion_failed_count; + expect_assertion = true; + + BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast( base ), expected_assertion ); // should assert + + BOOST_TEST_EQ( assertion_failed_count, old_count + 1 ); + expect_assertion = false; +} + +#endif + +static void test_polymorphic_pointer_downcast_intrusive_fail() +{ + boost::intrusive_ptr base (new Base); + + int old_count = assertion_failed_count; + expect_assertion = true; + + BOOST_TEST_THROWS( boost::polymorphic_pointer_downcast( base ), expected_assertion); // should assert + + BOOST_TEST_EQ( assertion_failed_count, old_count + 1 ); + expect_assertion = false; +} + +int main() +{ + test_polymorphic_cast(); + test_polymorphic_pointer_cast(); + test_polymorphic_downcast(); + test_polymorphic_pointer_downcast_builtin(); + test_polymorphic_pointer_downcast_boost_shared(); + test_polymorphic_pointer_downcast_intrusive(); + test_polymorphic_cast_fail(); + test_polymorphic_pointer_cast_fail(); + test_polymorphic_downcast_fail(); + test_polymorphic_pointer_downcast_builtin_fail(); + test_polymorphic_pointer_downcast_boost_shared_fail(); + test_polymorphic_pointer_downcast_intrusive_fail(); + +#ifndef BOOST_NO_CXX11_SMART_PTR + test_polymorphic_pointer_downcast_std_shared(); + test_polymorphic_pointer_downcast_std_shared_fail(); +#endif + + return boost::report_errors(); +} -- cgit v1.2.3