From 2841e8e038d462950f94df3e616d4cfeb7ef0c12 Mon Sep 17 00:00:00 2001 From: Fuchsia Authors Date: Sat, 20 Aug 2022 00:14:52 +0000 Subject: [PATCH] third_party/fuchsia: Copybara import of the fit library - f9f809cc1015ee6bc529728aecac09b0a20d17fa [fit] static_assert for bad function instantiation - fa85e608bba04b8e7e316f8159b29fa0b735f6ff [fit] Fix internal class template parameters Manually fix negative compilation test failures for pw::Function. GitOrigin-RevId: f9f809cc1015ee6bc529728aecac09b0a20d17fa Change-Id: Ie23320ca819c41546071df13e99bb626beed8537 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/107660 Commit-Queue: Auto-Submit Pigweed-Auto-Submit: Wyatt Hepler Reviewed-by: Erik Gilling --- pw_function/function_test.cc | 8 +-- .../sdk/lib/fit/include/lib/fit/function.h | 62 +++++++++++-------- .../fit/include/lib/fit/function_internal.h | 2 +- 3 files changed, 41 insertions(+), 31 deletions(-) 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.