diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 33d993e2..9664797b 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -172,7 +172,7 @@ namespace etl //************************************************************************* // Construct from a function pointer. //************************************************************************* - delegate(function_ptr fp) ETL_NOEXCEPT + explicit delegate(function_ptr fp) ETL_NOEXCEPT { assign(fp, function_ptr_stub); } @@ -534,7 +534,14 @@ namespace etl //************************************************************************* delegate& operator=(function_ptr fp) ETL_NOEXCEPT { - assign(fp, function_ptr_stub); + if (fp == ETL_NULLPTR) + { + invocation.clear(); + } + else + { + assign(fp, function_ptr_stub); + } return *this; } diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index b8445166..d57ad1f8 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -372,6 +372,27 @@ namespace CHECK_FALSE(d.is_valid()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_is_valid_after_init_empty_braces) + { + etl::delegate d = {}; + + CHECK_FALSE(d.is_valid()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_is_valid_after_assign_empty_braces) + { + auto lambda = [] { + }; + + etl::delegate d(lambda); + + CHECK_TRUE(d.is_valid()); + d = {}; + CHECK_FALSE(d.is_valid()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_void) {