pw_function: Error message for bad instantiations
Display a clear error message when pw::Function is instantiated with
anything other than a function type.
Change-Id: I658b28118c927e38a7ed523b0884ed7131856a32
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/65746
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
Reviewed-by: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_function/function_test.cc b/pw_function/function_test.cc
index 9fc01d3..0c2b89a 100644
--- a/pw_function/function_test.cc
+++ b/pw_function/function_test.cc
@@ -20,6 +20,27 @@
namespace pw {
namespace {
+// TODO(pwbug/47): Convert this to a compilation failure test.
+#if defined(PW_COMPILE_FAIL_TEST_CannotInstantiateWithNonFunction)
+
+[[maybe_unused]] Function<int> function_pointer;
+
+#elif defined(PW_COMPILE_FAIL_TEST_CannotInstantiateWithFunctionPointer1)
+
+[[maybe_unused]] Function<void (*)()> function_pointer;
+
+#elif defined(PW_COMPILE_FAIL_TEST_CannotInstantiateWithFunctionPointer2)
+
+[[maybe_unused]] void SomeFunction(int);
+
+[[maybe_unused]] Function<decltype(&SomeFunction)> function_pointer;
+
+#elif defined(PW_COMPILE_FAIL_TEST_CannotInstantiateWithFunctionReference)
+
+[[maybe_unused]] Function<void (&)()> function_pointer;
+
+#endif // compile fail tests
+
// Ensure that Function can be constant initialized.
[[maybe_unused]] PW_CONSTINIT Function<void()> can_be_constant_initialized;