diff options
| author | Martin Hořeňovský | 2017-02-09 12:57:01 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2017-02-09 12:57:01 +0100 |
| commit | 73159ace3d84b3cf01a126d6edefde196cceb621 (patch) | |
| tree | 0b56ba78f3030bc2755bd782e7ce697289980e98 /include | |
| parent | 9952dda524e5578d808e2c267fff0799f228cbd2 (diff) | |
| download | catch3-73159ace3d84b3cf01a126d6edefde196cceb621.tar.gz | |
REQUIRE_THROWS_AS now catches exception by const&
Prevents some warnings caused by catching complex types by value.
Closes #542
Diffstat (limited to 'include')
| -rw-r--r-- | include/internal/catch_capture.hpp | 3 | ||||
| -rw-r--r-- | include/internal/catch_type_traits.hpp | 47 |
2 files changed, 49 insertions, 1 deletions
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index ae10f58a..8abc536b 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -16,6 +16,7 @@ #include "catch_tostring.h" #include "catch_interfaces_runner.h" #include "catch_compiler_capabilities.h" +#include "catch_type_traits.hpp" /////////////////////////////////////////////////////////////////////////////// @@ -93,7 +94,7 @@ static_cast<void>(expr); \ __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ } \ - catch( exceptionType ) { \ + catch( Catch::add_const<Catch::add_lvalue_reference<exceptionType>::type>::type ) { \ __catchResult.captureResult( Catch::ResultWas::Ok ); \ } \ catch( ... ) { \ diff --git a/include/internal/catch_type_traits.hpp b/include/internal/catch_type_traits.hpp new file mode 100644 index 00000000..9be89162 --- /dev/null +++ b/include/internal/catch_type_traits.hpp @@ -0,0 +1,47 @@ +/* + * Created by Martin on 08/02/2017. + * + * 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) + */ +#ifndef TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED + +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) +#include <type_traits> +#endif + + +namespace Catch { + +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) + + template <typename T> + using add_lvalue_reference = std::add_lvalue_reference<T>; + + template <typename T> + using add_const = std::add_const<T>; + +#else + + template <typename T> + struct add_const { + typedef const T type; + }; + + template <typename T> + struct add_lvalue_reference { + typedef T& type; + }; + template <typename T> + struct add_lvalue_reference<T&> { + typedef T& type; + }; + // No && overload, because that is C++11, in which case we have + // proper type_traits implementation from the standard library + +#endif + +} + +#endif // TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED |