diff --git a/pw_function/function_test.cc b/pw_function/function_test.cc index 2f25cfc7df..b7309c3169 100644 --- a/pw_function/function_test.cc +++ b/pw_function/function_test.cc @@ -22,24 +22,24 @@ namespace pw { namespace { #if PW_NC_TEST(CannotInstantiateWithNonFunction) -PW_NC_EXPECT("incomplete type|undefined template"); +PW_NC_EXPECT("must be instantiated with a function type"); [[maybe_unused]] Function function_pointer; #elif PW_NC_TEST(CannotInstantiateWithFunctionPointer1) -PW_NC_EXPECT("incomplete type|undefined template"); +PW_NC_EXPECT("must be instantiated with a function type"); [[maybe_unused]] Function function_pointer; #elif PW_NC_TEST(CannotInstantiateWithFunctionPointer2) -PW_NC_EXPECT("incomplete type|undefined template"); +PW_NC_EXPECT("must be instantiated with a function type"); [[maybe_unused]] void SomeFunction(int); [[maybe_unused]] Function function_pointer; #elif PW_NC_TEST(CannotInstantiateWithFunctionReference) -PW_NC_EXPECT("incomplete type|undefined template"); +PW_NC_EXPECT("must be instantiated with a function type"); [[maybe_unused]] Function function_pointer; diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function.h index e11970550d..cc7ff00cf8 100644 --- a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function.h +++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function.h @@ -5,17 +5,27 @@ #ifndef LIB_FIT_INCLUDE_LIB_FIT_FUNCTION_H_ #define LIB_FIT_INCLUDE_LIB_FIT_FUNCTION_H_ +#include + #include "function_internal.h" #include "traits.h" #include "utility_internal.h" namespace fit { -template -class function_impl; +template +class function_impl { + static_assert(std::is_function::value, + "fit::function must be instantiated with a function type, such as void() or " + "int(char*, bool)"); +}; -template -class callback_impl; +template +class callback_impl { + static_assert(std::is_function::value, + "fit::callback must be instantiated with a function type, such as void() or " + "int(char*, bool)"); +}; // The default size allowance for storing a target inline within a function // object, in bytes. This default allows for inline storage of targets @@ -302,30 +312,30 @@ class function_impl final } }; -template -void swap(function_impl& a, - function_impl& b) { +template +void swap(function_impl& a, + function_impl& b) { a.swap(b); } -template -bool operator==(const function_impl& f, +template +bool operator==(const function_impl& f, decltype(nullptr)) { return !f; } -template +template bool operator==(decltype(nullptr), - const function_impl& f) { + const function_impl& f) { return !f; } -template -bool operator!=(const function_impl& f, +template +bool operator!=(const function_impl& f, decltype(nullptr)) { return !!f; } -template +template bool operator!=(decltype(nullptr), - const function_impl& f) { + const function_impl& f) { return !!f; } @@ -458,30 +468,30 @@ class callback_impl final } }; -template -void swap(callback_impl& a, - callback_impl& b) { +template +void swap(callback_impl& a, + callback_impl& b) { a.swap(b); } -template -bool operator==(const callback_impl& f, +template +bool operator==(const callback_impl& f, decltype(nullptr)) { return !f; } -template +template bool operator==(decltype(nullptr), - const callback_impl& f) { + const callback_impl& f) { return !f; } -template -bool operator!=(const callback_impl& f, +template +bool operator!=(const callback_impl& f, decltype(nullptr)) { return !!f; } -template +template bool operator!=(decltype(nullptr), - const callback_impl& f) { + const callback_impl& f) { return !!f; } diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h index 649373c8e1..0e226e99d4 100644 --- a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h +++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h @@ -179,7 +179,7 @@ constexpr target_ops target::ops = { &target::target_type_id, &target::get, &target::invoke, &target::move, &target::destroy}; -template +template class function_base; // Function implementation details.