Skip to content

Commit

Permalink
Fix an issue where FU2_HAS_NO_FUNCTIONAL_HEADER was always set
Browse files Browse the repository at this point in the history
* This caused that fu2::bad_function_call was thrown instead of
  the intended std::bad_function_call. fu2::bad_function_call is only
  intended to be used if FU2_WITH_NO_FUNCTIONAL_HEADER is set.
  • Loading branch information
Naios committed Sep 24, 2019
1 parent ebc1936 commit 5b8e6de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 7 additions & 6 deletions include/function2/function2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
#endif
#endif // FU2_WITH_DISABLED_EXCEPTIONS
// - FU2_HAS_NO_FUNCTIONAL_HEADER
#if !defined(FU2_WITH_NO_FUNCTIONAL_HEADER) || \
!defined(FU2_NO_FUNCTIONAL_HEADER) || \
#if !defined(FU2_WITH_NO_FUNCTIONAL_HEADER) && \
!defined(FU2_NO_FUNCTIONAL_HEADER) && \
!defined(FU2_HAS_DISABLED_EXCEPTIONS)
#define FU2_HAS_NO_FUNCTIONAL_HEADER
#include <functional>
#else
#define FU2_HAS_NO_FUNCTIONAL_HEADER
#endif
// - FU2_HAS_CXX17_NOEXCEPT_FUNCTION_TYPE
#if defined(FU2_WITH_CXX17_NOEXCEPT_FUNCTION_TYPE)
Expand Down Expand Up @@ -461,7 +462,7 @@ struct bad_function_call : std::exception {
return "bad function call";
}
};
#elif
#else
using std::bad_function_call;
#endif
#endif
Expand Down Expand Up @@ -1717,13 +1718,13 @@ using function_view = function_base<false, true, capacity_default, //
/// Exception type that is thrown when invoking empty function objects
/// and exception support isn't disabled.
///
/// Exception suport is enabled if
/// Exception support is enabled if
/// the template parameter 'Throwing' is set to true (default).
///
/// This type will default to std::bad_function_call if the
/// functional header is used, otherwise the library provides its own type.
///
/// You may disable the inclusion of the functionl header
/// You may disable the inclusion of the functional header
/// through defining `FU2_WITH_NO_FUNCTIONAL_HEADER`.
///
using detail::type_erasure::invocation_table::bad_function_call;
Expand Down
6 changes: 6 additions & 0 deletions test/empty-function-call-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ TYPED_TEST(AllEmptyFunctionCallTests, CallSucceedsIfNonEmptyRef) {
}

#if !defined(FU2_HAS_DISABLED_EXCEPTIONS)
#ifndef FU2_HAS_NO_FUNCTIONAL_HEADER
static_assert(std::is_same<fu2::bad_function_call, //
std::bad_function_call>::value,
"Wrong fu2::bad_function_call exposed!");
#endif

TYPED_TEST(AllEmptyFunctionCallTests, CallThrowsIfEmpty) {
typename TestFixture::template left_t<bool()> left;
EXPECT_THROW(left(), fu2::bad_function_call);
Expand Down

0 comments on commit 5b8e6de

Please sign in to comment.