Compare commits

..

7 Commits

Author SHA1 Message Date
9b99dd5f60 Add tests for throw_line 2018-09-27 08:26:29 +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
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
7 changed files with 212 additions and 3 deletions

View File

@ -16,7 +16,7 @@ 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)

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)

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

@ -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();
}