diff --git a/README.md b/README.md index 801ee65c..5f8a211b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ Embedded Template Library (ETL) ------------------------- -AppVeyor [![Build status](https://ci.appveyor.com/api/projects/status/b7jgecv7unqjw4u0/branch/master?svg=true)](https://ci.appveyor.com/project/jwellbelove/etl/branch/master) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) +AppVeyor +[![Build status](https://ci.appveyor.com/api/projects/status/b7jgecv7unqjw4u0/branch/master?svg=true)](https://ci.appveyor.com/project/jwellbelove/etl/branch/master) ![build status](https://gitlab.com/ETLCPP/etl/badges/master/build.svg) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3c14cd918ccf40008d0bcd7b083d5946)](https://www.codacy.com/manual/jwellbelove/etl?utm_source=github.com&utm_medium=referral&utm_content=ETLCPP/etl&utm_campaign=Badge_Grade) +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) **Motivation** diff --git a/include/etl/delegate.h b/include/etl/delegate.h index 4cd8a595..e5a8941e 100644 --- a/include/etl/delegate.h +++ b/include/etl/delegate.h @@ -49,13 +49,44 @@ Original publication: https://www.codeproject.com/Articles/1170503/The-Impossibl #define ETL_DELEGATE_INCLUDED #include "platform.h" +#include "error_handler.h" +#include "exception.h" #if ETL_CPP11_SUPPORTED == 0 #error NOT SUPPORTED FOR C++03 OR BELOW #endif +#undef ETL_FILE +#define ETL_FILE "51" + namespace etl { + //*************************************************************************** + /// The base class for delegate exceptions. + //*************************************************************************** + class delegate_exception : public exception + { + public: + + delegate_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + /// The exception thrown when the delegate is uninitialised. + //*************************************************************************** + class delegate_uninitialised : public delegate_exception + { + public: + + delegate_uninitialised(string_type file_name_, numeric_type line_number_) + : delegate_exception(ETL_ERROR_TEXT("delegate:uninitialised", ETL_FILE"A"), file_name_, line_number_) + { + } + }; + template class delegate; template @@ -166,6 +197,8 @@ namespace etl //************************************************************************* TReturn operator()(TParams... args) const { + ETL_ASSERT(invocation.stub != nullptr, ETL_ERROR(delegate_uninitialised)); + return (*invocation.stub)(invocation.object, args...); } @@ -353,4 +386,6 @@ namespace etl }; } +#undef ETL_FILE + #endif diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 5a8d0546..a0fc5e0f 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -122,24 +122,31 @@ namespace etl //*************************************************************************** #if defined(ETL_NO_CHECKS) #define ETL_ASSERT(b, e) // Does nothing. + #define ETL_ALWAYS_ASSERT(e) // Does nothing. #elif defined(ETL_THROW_EXCEPTIONS) #if defined(ETL_LOG_ERRORS) #define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e));}} // If the condition fails, calls the error handler then throws an exception. + #define ETL_ALWAYS_ASSERT(e) {etl::error_handler::error((e)); throw((e));} // Calls the error handler then throws an exception. #else #define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception. + #define ETL_ALWAYS_ASSERT(e) {throw((e));} // Throws an exception. #endif #else #if defined(ETL_LOG_ERRORS) #if defined(NDEBUG) #define ETL_ASSERT(b, e) {if(!(b)) {etl::error_handler::error((e));}} // If the condition fails, calls the error handler + #define ETL_ALWAYS_ASSERT(e) {etl::error_handler::error((e));} // Calls the error handler #else - #define ETL_ASSERT(b, e) {if(!(b)) {etl::error_handler::error((e));} assert((b));} // If the condition fails, calls the error handler then asserts. + #define ETL_ASSERT(b, e) {if(!(b)) {etl::error_handler::error((e)); assert((b));}} // If the condition fails, calls the error handler then asserts. + #define ETL_ALWAYS_ASSERT(e) {etl::error_handler::error((e)); assert(true);} // Calls the error handler then asserts. #endif #else #if defined(NDEBUG) #define ETL_ASSERT(b, e) // Does nothing. + #define ETL_ALWAYS_ASSERT(e) // Does nothing. #else #define ETL_ASSERT(b, e) assert((b)) // If the condition fails, asserts. + #define ETL_ALWAYS_ASSERT(e) assert(true) // Asserts. #endif #endif #endif diff --git a/include/etl/file_error_numbers.txt b/include/etl/file_error_numbers.txt index 4abc3060..281c75ea 100644 --- a/include/etl/file_error_numbers.txt +++ b/include/etl/file_error_numbers.txt @@ -47,4 +47,5 @@ 47 queue_spsc_atomic 48 queue_mpmc_mutex 49 type_select -50 binary \ No newline at end of file +50 binary +51 delegate diff --git a/include/etl/version.h b/include/etl/version.h index c40bb716..d6c8fd61 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 35 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_PATCH 3 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 2af50f96..abbd76d5 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "14.35.2", + "version": "14.35.3", "authors": { "name": "John Wellbelove", "email": "" diff --git a/library.properties b/library.properties index c5113f6b..449e4e02 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=14.35.2 +version=14.35.3 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 67791987..626c4a21 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.35.3 +Added assert when calling uninitialised delegate. + =============================================================================== 14.35.2 Fixed incorrect result when rounding up to integral part. diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index e76a3030..faf21321 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -27,6 +27,7 @@ SOFTWARE. ******************************************************************************/ #include "UnitTest++.h" +#include "ExtraCheckMacros.h" #include "etl/delegate.h" @@ -167,6 +168,8 @@ namespace CHECK(!d.is_valid()); CHECK(!d); + + CHECK_THROW(d(), etl::delegate_uninitialised); } //************************************************************************* @@ -176,6 +179,7 @@ namespace CHECK(d.is_valid()); CHECK(d); + CHECK_NO_THROW(d()); } //************************************************************************* diff --git a/test/vs2017/Debug No Unit Tests/.gitignore b/test/vs2017/Debug No Unit Tests/.gitignore new file mode 100644 index 00000000..829cc2ea --- /dev/null +++ b/test/vs2017/Debug No Unit Tests/.gitignore @@ -0,0 +1 @@ +*.idb