|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85081 - in trunk: boost/variant libs/variant/test
From: antoshkka_at_[hidden]
Date: 2013-07-19 07:40:06
Author: apolukhin
Date: 2013-07-19 07:40:06 EDT (Fri, 19 Jul 2013)
New Revision: 85081
URL: http://svn.boost.org/trac/boost/changeset/85081
Log:
Make Boost.Variant work on exception-disabled environments (refs #8717)
Text files modified:
trunk/boost/variant/get.hpp | 7 ++++---
trunk/boost/variant/variant.hpp | 35 +++++++++++++++++++++--------------
trunk/boost/variant/visitor_ptr.hpp | 3 ++-
trunk/libs/variant/test/Jamfile.v2 | 11 +++++++++++
trunk/libs/variant/test/recursive_variant_test.cpp | 35 ++++++++++++++++++++++++++++++++---
5 files changed, 70 insertions(+), 21 deletions(-)
Modified: trunk/boost/variant/get.hpp
==============================================================================
--- trunk/boost/variant/get.hpp Fri Jul 19 03:52:40 2013 (r85080)
+++ trunk/boost/variant/get.hpp 2013-07-19 07:40:06 EDT (Fri, 19 Jul 2013) (r85081)
@@ -17,6 +17,7 @@
#include "boost/config.hpp"
#include "boost/detail/workaround.hpp"
+#include "boost/throw_exception.hpp"
#include "boost/utility/addressof.hpp"
#include "boost/variant/variant_fwd.hpp"
@@ -41,7 +42,7 @@
{
public: // std::exception implementation
- virtual const char * what() const throw()
+ virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
{
return "boost::bad_get: "
"failed value get using boost::get";
@@ -177,7 +178,7 @@
U_ptr result = get<U>(&operand);
if (!result)
- throw bad_get();
+ boost::throw_exception(bad_get());
return *result;
}
@@ -193,7 +194,7 @@
U_ptr result = get<const U>(&operand);
if (!result)
- throw bad_get();
+ boost::throw_exception(bad_get());
return *result;
}
Modified: trunk/boost/variant/variant.hpp
==============================================================================
--- trunk/boost/variant/variant.hpp Fri Jul 19 03:52:40 2013 (r85080)
+++ trunk/boost/variant/variant.hpp 2013-07-19 07:40:06 EDT (Fri, 19 Jul 2013) (r85081)
@@ -3,13 +3,15 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
-// Copyright (c) 2002-2003
-// Eric Friedman, Itay Maman
+// Copyright (c) 2002-2003 Eric Friedman, Itay Maman
+// Copyright (c) 2012-2013 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)
+// Thanks to Adam Romanek for providing patches for exception-disabled env.
+
#ifndef BOOST_VARIANT_VARIANT_HPP
#define BOOST_VARIANT_VARIANT_HPP
@@ -37,6 +39,7 @@
#include "boost/variant/detail/generic_result_type.hpp"
#include "boost/variant/detail/move.hpp"
+#include "boost/detail/no_exceptions_support.hpp"
#include "boost/detail/reference_content.hpp"
#include "boost/aligned_storage.hpp"
#include "boost/blank.hpp"
@@ -789,12 +792,12 @@
// ...destroy lhs content...
lhs_content.~LhsT(); // nothrow
- try
+ BOOST_TRY
{
// ...and attempt to copy rhs content into lhs storage:
copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
}
- catch (...)
+ BOOST_CATCH (...)
{
// In case of failure, restore backup content to lhs storage...
new(lhs_.storage_.address())
@@ -803,8 +806,9 @@
); // nothrow
// ...and rethrow:
- throw;
+ BOOST_RETHROW;
}
+ BOOST_CATCH_END
// In case of success, indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
@@ -822,12 +826,12 @@
// ...destroy lhs content...
lhs_content.~LhsT(); // nothrow
- try
+ BOOST_TRY
{
// ...and attempt to copy rhs content into lhs storage:
copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
}
- catch (...)
+ BOOST_CATCH (...)
{
// In case of failure, copy backup pointer to lhs storage...
new(lhs_.storage_.address())
@@ -837,8 +841,9 @@
lhs_.indicate_backup_which( lhs_.which() ); // nothrow
// ...and rethrow:
- throw;
+ BOOST_RETHROW;
}
+ BOOST_CATCH_END
// In case of success, indicate new content type...
lhs_.indicate_which(rhs_which_); // nothrow
@@ -1885,13 +1890,13 @@
// Destroy lhs's content...
lhs_.destroy_content(); // nothrow
- try
+ BOOST_TRY
{
// ...and attempt to copy rhs's content into lhs's storage:
new(lhs_.storage_.address())
RhsT( rhs_content );
}
- catch (...)
+ BOOST_CATCH (...)
{
// In case of failure, default-construct fallback type in lhs's storage...
new (lhs_.storage_.address())
@@ -1903,8 +1908,9 @@
); // nothrow
// ...and rethrow:
- throw;
+ BOOST_RETHROW;
}
+ BOOST_CATCH_END
// In the event of success, indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
@@ -2029,13 +2035,13 @@
// Destroy lhs's content...
lhs_.destroy_content(); // nothrow
- try
+ BOOST_TRY
{
// ...and attempt to copy rhs's content into lhs's storage:
new(lhs_.storage_.address())
RhsT( detail::variant::move(rhs_content) );
}
- catch (...)
+ BOOST_CATCH (...)
{
// In case of failure, default-construct fallback type in lhs's storage...
new (lhs_.storage_.address())
@@ -2047,8 +2053,9 @@
); // nothrow
// ...and rethrow:
- throw;
+ BOOST_RETHROW;
}
+ BOOST_CATCH_END
// In the event of success, indicate new content type:
lhs_.indicate_which(rhs_which_); // nothrow
Modified: trunk/boost/variant/visitor_ptr.hpp
==============================================================================
--- trunk/boost/variant/visitor_ptr.hpp Fri Jul 19 03:52:40 2013 (r85080)
+++ trunk/boost/variant/visitor_ptr.hpp 2013-07-19 07:40:06 EDT (Fri, 19 Jul 2013) (r85081)
@@ -18,6 +18,7 @@
#include "boost/mpl/eval_if.hpp"
#include "boost/mpl/identity.hpp"
+#include "boost/throw_exception.hpp"
#include "boost/type_traits/add_reference.hpp"
#include "boost/type_traits/is_reference.hpp"
#include "boost/type_traits/is_void.hpp"
@@ -64,7 +65,7 @@
template <typename U>
result_type operator()(const U&) const
{
- throw bad_visit();
+ boost::throw_exception(bad_visit());
}
#if !defined(BOOST_NO_VOID_RETURNS)
Modified: trunk/libs/variant/test/Jamfile.v2
==============================================================================
--- trunk/libs/variant/test/Jamfile.v2 Fri Jul 19 03:52:40 2013 (r85080)
+++ trunk/libs/variant/test/Jamfile.v2 2013-07-19 07:40:06 EDT (Fri, 19 Jul 2013) (r85081)
@@ -1,6 +1,7 @@
# Boost.Variant Library test Jamfile
#
# Copyright (C) 2003, Eric Friedman, Itay Maman.
+# Copyright (C) 2013, Antony Polukhin.
#
# This material is provided "as is", with absolutely no warranty expressed
# or implied. Any use is at your own risk.
@@ -35,6 +36,16 @@
[ run variant_multivisit_test.cpp ]
[ run hash_variant_test.cpp ]
[ run rvalue_test.cpp ]
+ [ run recursive_variant_test.cpp : : : <define>BOOST_NO_EXCEPTIONS
+ <toolset>gcc-4.3:<cxxflags>-fno-exceptions
+ <toolset>gcc-4.4:<cxxflags>-fno-exceptions
+ <toolset>gcc-4.5:<cxxflags>-fno-exceptions
+ <toolset>gcc-4.6:<cxxflags>-fno-exceptions
+ <toolset>gcc-4.7:<cxxflags>-fno-exceptions
+ <toolset>gcc-4.8:<cxxflags>-fno-exceptions
+ <toolset>clang:<cxxflags>-fno-exceptions
+ : variant_noexcept_test
+ ]
;
Modified: trunk/libs/variant/test/recursive_variant_test.cpp
==============================================================================
--- trunk/libs/variant/test/recursive_variant_test.cpp Fri Jul 19 03:52:40 2013 (r85080)
+++ trunk/libs/variant/test/recursive_variant_test.cpp 2013-07-19 07:40:06 EDT (Fri, 19 Jul 2013) (r85081)
@@ -3,14 +3,43 @@
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
-// Copyright (c) 2003
-// Eric Friedman, Itay Maman
+// Copyright (c) 2003 Eric Friedman, Itay Maman
+// Copyright (c) 2013 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)
-#include "boost/test/minimal.hpp"
+
+// This file is used in two test cases:
+//
+// 1) recursive_variant_test.cpp that tests recursive usage of variant
+//
+// 2) variant_noexcept_test that tests Boost.Variant ability to compile
+// and work with disabled exceptions
+
+#ifdef BOOST_NO_EXCEPTIONS
+// `boost/test/minimal.hpp` cannot work with exceptions disabled,
+// so we need the following workarounds for that case:
+namespace boost {
+ int exit_success = 0;
+}
+
+int test_main(int , char* []);
+
+int main( int argc, char* argv[] )
+{
+ return test_main(argc, argv);
+}
+
+#include <stdlib.h>
+#define BOOST_CHECK(exp) if (!(exp)) exit(EXIT_FAILURE)
+
+#else // BOOST_NO_EXCEPTIONS
+# include "boost/test/minimal.hpp"
+#endif // BOOST_NO_EXCEPTIONS
+
+
#include "boost/variant.hpp"
#include "boost/mpl/vector.hpp"
#include "boost/mpl/copy.hpp"
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk