Compare commits

..

21 Commits

Author SHA1 Message Date
43a57d518c msvc warning workaround, thanks bersbersbers 2019-10-15 13:36:12 -07:00
e2e802e508 dist: trusty 2019-08-20 16:27:13 -07:00
5143552817 throw() -> BOOST_NOEXCEPT_OR_NOTHROW 2019-06-06 15:33:45 -07:00
1e507924ce Mark throw_exception with BOOST_NORETURN. Closes #12. 2019-06-03 03:06:40 +03:00
50c34dee24 Switch Appveyor to 2015 image 2019-04-14 17:51:51 +03:00
37dfb7fe92 Remove essentials from yml files 2018-12-22 05:16:16 +02:00
9dfba607d9 Update .yml files 2018-12-18 21:58:55 +02:00
074bc77efb Merge branch 'feature/wrapexcept' into develop 2018-09-30 04:07:21 +03:00
9d5b953dcf Merge branch 'develop' 2018-09-30 04:05:46 +03:00
eafb1c877b Add 'unsupported' comment to CMakeLists.txt 2018-09-30 04:05:09 +03:00
dd7d2a273c Merge branch 'feature/more-tests' into feature/wrapexcept 2018-09-27 08:27:02 +03:00
9b99dd5f60 Add tests for throw_line 2018-09-27 08:26:29 +03:00
322d7611af Use boost::wrapexcept<E> as the thrown exception type 2018-09-27 08:13:59 +03:00
56dd1c4111 Add/use exception_detail::enable_both 2018-09-27 07:39:18 +03:00
a732dfad3c Add boost::exception, exception_ptr tests to throw_from_library_test as well 2018-09-27 07:23:52 +03:00
6845ba892d Add test that uses boost::exception_ptr 2018-09-27 07:15:53 +03:00
a17f4bad42 Add test that catches by boost::exception 2018-09-27 07:10:41 +03:00
c807ae9201 Merge branch 'fix-c4668' of https://github.com/pkolbus/throw_exception into feature/pr-7 2018-09-27 06:27:32 +03:00
40e067d7b7 Merge commit '56d65d5f625ed118f6052cc8f924f8ec21913089' 2018-09-24 07:09:18 +03:00
f796dd892a Fix MSVC C4668 in exception.hpp
Fix MSVC C4668 warnings (undefined preprocessor macro) for __GNUC__ and __GNUC_MINOR__ by checking if __GNUC__ is defined first.
2018-03-26 22:39:26 -05:00
f5022b5ca8 Fix MSVC C4668 in throw_exception.hpp
Fix MSVC C4668 warnings (undefined preprocessor macro) for __GNUC__ and __GNUC_MINOR__ by checking if __GNUC__ is defined first.
2018-03-26 22:38:33 -05:00
13 changed files with 326 additions and 66 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.vscode/ipch/*

View File

@ -6,6 +6,8 @@ language: cpp
sudo: false
dist: trusty
python: "2.7"
branches:
@ -110,7 +112,7 @@ matrix:
- os: linux
compiler: g++-8
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
@ -120,7 +122,7 @@ matrix:
- os: linux
compiler: g++-8
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17 UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
addons:
apt:
packages:
@ -227,6 +229,17 @@ matrix:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- os: linux
compiler: clang++-7
env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- clang-7
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
- os: linux
compiler: clang++-6.0
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17 UBSAN_OPTIONS=print_stacktrace=1
@ -263,8 +276,6 @@ install:
- cd ..
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/build
- git submodule update --init libs/config
- git submodule update --init tools/boostdep
- cp -r $TRAVIS_BUILD_DIR/* libs/throw_exception
- python tools/boostdep/depinst/depinst.py throw_exception

View File

@ -2,6 +2,9 @@
# 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
# Partial (add_subdirectory only) and experimental CMake support
# Subject to change; please do not rely on the contents of this file yet
cmake_minimum_required(VERSION 3.5)
project(BoostThrowException LANGUAGES CXX)

View File

@ -1,4 +1,4 @@
# Copyright 2016-2018 Peter Dimov
# Copyright 2016-2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
@ -14,26 +14,24 @@ branches:
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-14.0
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0,msvc-14.0
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1
CXXSTD: 14,17
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
@ -44,10 +42,8 @@ install:
- cd ..
- git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
- cd boost-root
- git submodule update --init tools/build
- git submodule update --init libs/config
- git submodule update --init tools/boostdep
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\throw_exception
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\throw_exception\
- python tools/boostdep/depinst/depinst.py throw_exception
- cmd /c bootstrap
- b2 -d0 headers
@ -57,4 +53,4 @@ build: off
test_script:
- PATH=%ADDPATH%%PATH%
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
- b2 -j 3 libs/throw_exception/test toolset=%TOOLSET% %CXXSTD%
- b2 -j3 libs/throw_exception/test toolset=%TOOLSET% %CXXSTD%

View File

@ -16,11 +16,12 @@ namespace boost { template <class T> class shared_ptr; }
namespace boost { namespace exception_detail { using boost::shared_ptr; } }
#endif
#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#if defined(__GNUC__) && (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma GCC system_header
#endif
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma warning(push,1)
#pragma warning(disable: 4265)
#endif
namespace
@ -165,7 +166,7 @@ boost
protected:
~error_info_container() throw()
~error_info_container() BOOST_NOEXCEPT_OR_NOTHROW
{
}
};
@ -233,7 +234,7 @@ boost
#ifdef __HP_aCC
//On HP aCC, this protected copy constructor prevents throwing boost::exception.
//On all other platforms, the same effect is achieved by the pure virtual destructor.
exception( exception const & x ) throw():
exception( exception const & x ) BOOST_NOEXCEPT_OR_NOTHROW:
data_(x.data_),
throw_function_(x.throw_function_),
throw_file_(x.throw_file_),
@ -242,7 +243,7 @@ boost
}
#endif
virtual ~exception() throw()
virtual ~exception() BOOST_NOEXCEPT_OR_NOTHROW
#ifndef __HP_aCC
= 0 //Workaround for HP aCC, =0 incorrectly leads to link errors.
#endif
@ -287,7 +288,7 @@ boost
inline
exception::
~exception() throw()
~exception() BOOST_NOEXCEPT_OR_NOTHROW
{
}
@ -337,7 +338,7 @@ boost
{
}
~error_info_injector() throw()
~error_info_injector() BOOST_NOEXCEPT_OR_NOTHROW
{
}
};
@ -398,7 +399,7 @@ boost
virtual void rethrow() const = 0;
virtual
~clone_base() throw()
~clone_base() BOOST_NOEXCEPT_OR_NOTHROW
{
}
};
@ -445,7 +446,7 @@ boost
copy_boost_exception(this,&x);
}
~clone_impl() throw()
~clone_impl() BOOST_NOEXCEPT_OR_NOTHROW
{
}
@ -472,6 +473,51 @@ boost
{
return exception_detail::clone_impl<T>(x);
}
template <class T>
struct
BOOST_SYMBOL_VISIBLE
wrapexcept:
public exception_detail::clone_impl<typename exception_detail::enable_error_info_return_type<T>::type>
{
typedef exception_detail::clone_impl<typename exception_detail::enable_error_info_return_type<T>::type> base_type;
public:
explicit
wrapexcept( typename exception_detail::enable_error_info_return_type<T>::type const & x ):
base_type( x )
{
}
~wrapexcept() BOOST_NOEXCEPT_OR_NOTHROW
{
}
};
namespace
exception_detail
{
template <class T>
struct
remove_error_info_injector
{
typedef T type;
};
template <class T>
struct
remove_error_info_injector< error_info_injector<T> >
{
typedef T type;
};
template <class T>
inline
wrapexcept<typename remove_error_info_injector<T>::type>
enable_both( T const & x )
{
return wrapexcept<typename remove_error_info_injector<T>::type>( enable_error_info( x ) );
}
}
}
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)

View File

@ -43,7 +43,7 @@
# define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x)
#endif
#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#if defined(__GNUC__) && (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
#pragma GCC system_header
#endif
#if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS)
@ -54,7 +54,7 @@ namespace boost
{
#ifdef BOOST_NO_EXCEPTIONS
void throw_exception( std::exception const & e ); // user defined
BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined
#else
@ -67,7 +67,7 @@ template<class E> BOOST_NORETURN inline void throw_exception( E const & e )
throw_exception_assert_compatibility(e);
#ifndef BOOST_EXCEPTION_DISABLE
throw enable_current_exception(enable_error_info(e));
throw exception_detail::enable_both( e );
#else
throw e;
#endif

View File

@ -14,6 +14,10 @@ run throw_exception_no_both_test.cpp ;
compile-fail throw_exception_fail.cpp ;
run throw_exception_test2.cpp ;
run throw_exception_test3.cpp ;
run throw_exception_test4.cpp ;
lib lib1_throw : lib1_throw.cpp : <define>LIB1_SOURCE=1 <link>shared:<define>LIB1_DYN_LINK=1 : : <link>shared:<define>LIB1_DYN_LINK=1 ;
lib lib2_throw : lib2_throw.cpp : <define>LIB2_SOURCE=1 <link>shared:<define>LIB2_DYN_LINK=1 : : <link>shared:<define>LIB2_DYN_LINK=1 ;
lib lib3_throw : lib3_throw.cpp : <define>LIB3_SOURCE=1 <link>shared:<define>LIB3_DYN_LINK=1 : : <link>shared:<define>LIB3_DYN_LINK=1 ;

View File

@ -5,27 +5,24 @@
#define BOOST_NO_EXCEPTIONS
#define BOOST_EXCEPTION_DISABLE
#include <boost/throw_exception.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cstdlib>
class my_exception: public std::exception { };
class my_exception: public std::exception {};
bool called=false;
int main()
{
boost::throw_exception( my_exception() );
return 1;
}
namespace
boost
{
void
throw_exception( std::exception const & )
{
called=true;
}
}
namespace boost
{
int
main()
{
boost::throw_exception(my_exception());
BOOST_TEST(called);
return boost::report_errors();
}
void throw_exception( std::exception const & )
{
std::exit( 0 );
}
} // namespace boost

View File

@ -4,27 +4,24 @@
//file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_NO_EXCEPTIONS
#include <boost/throw_exception.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <cstdlib>
class my_exception: public std::exception { };
class my_exception: public std::exception {};
bool called=false;
int main()
{
boost::throw_exception( my_exception() );
return 1;
}
namespace
boost
{
void
throw_exception( std::exception const & )
{
called=true;
}
}
namespace boost
{
int
main()
{
boost::throw_exception(my_exception());
BOOST_TEST(called);
return boost::report_errors();
}
void throw_exception( std::exception const & )
{
std::exit( 0 );
}
} // namespace boost

View File

@ -0,0 +1,28 @@
// Copyright 2018 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 <boost/throw_exception.hpp>
#include <boost/detail/lightweight_test.hpp>
class my_exception: public std::exception
{
};
class my_exception2: public std::exception, public boost::exception
{
};
int main()
{
BOOST_TEST_THROWS( boost::throw_exception( my_exception() ), boost::exception );
BOOST_TEST_THROWS( boost::throw_exception( my_exception2() ), boost::exception );
BOOST_TEST_THROWS( BOOST_THROW_EXCEPTION( my_exception() ), boost::exception );
BOOST_TEST_THROWS( BOOST_THROW_EXCEPTION( my_exception2() ), boost::exception );
return boost::report_errors();
}

View File

@ -0,0 +1,71 @@
// Copyright 2018 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 <boost/throw_exception.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
class my_exception: public std::exception
{
};
class my_exception2: public std::exception, public boost::exception
{
};
int main()
{
try
{
boost::throw_exception( my_exception() );
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
try
{
boost::throw_exception( my_exception2() );
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
try
{
BOOST_THROW_EXCEPTION( my_exception() );
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
try
{
BOOST_THROW_EXCEPTION( my_exception2() );
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
return boost::report_errors();
}

View File

@ -0,0 +1,47 @@
// Copyright 2018 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 <boost/throw_exception.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/detail/lightweight_test.hpp>
class my_exception: public std::exception
{
};
class my_exception2: public std::exception, public boost::exception
{
};
int main()
{
try
{
BOOST_THROW_EXCEPTION( my_exception() );
}
catch( boost::exception const & x )
{
int const * line = boost::get_error_info<boost::throw_line>( x );
BOOST_TEST( line != 0 );
BOOST_TEST_EQ( *line, 24 );
}
try
{
BOOST_THROW_EXCEPTION( my_exception2() );
}
catch( boost::exception const & x )
{
int const * line = boost::get_error_info<boost::throw_line>( x );
BOOST_TEST( line != 0 );
BOOST_TEST_EQ( *line, 36 );
}
return boost::report_errors();
}

View File

@ -8,13 +8,72 @@
#include "lib1_throw.hpp"
#include "lib2_throw.hpp"
#include "lib3_throw.hpp"
#include <boost/exception/exception.hpp>
#include <boost/exception_ptr.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
void test_catch_by_type()
{
BOOST_TEST_THROWS( lib1::f(), lib1::exception );
BOOST_TEST_THROWS( lib2::f(), lib2::exception );
BOOST_TEST_THROWS( lib3::f(), lib3::exception );
}
void test_catch_by_exception()
{
BOOST_TEST_THROWS( lib2::f(), boost::exception );
BOOST_TEST_THROWS( lib3::f(), boost::exception );
}
void test_exception_ptr()
{
try
{
lib2::f();
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib2::exception );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
try
{
lib3::f();
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), lib3::exception );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
}
void test_throw_line()
{
try
{
lib3::f();
}
catch( boost::exception const & x )
{
int const * line = boost::get_error_info<boost::throw_line>( x );
BOOST_TEST( line != 0 );
BOOST_TEST_EQ( *line, 13 );
}
}
int main()
{
test_catch_by_type();
test_catch_by_exception();
test_exception_ptr();
test_throw_line();
return boost::report_errors();
}