From 0180a7c9bdf84c284ddc4ea4e9ce4b2b2adf0f9a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 4 Oct 2020 14:24:52 +0100 Subject: [PATCH] Reduced warnings from cppcheck v2.2 --- include/etl/error_handler.h | 2 +- include/etl/function.h | 28 +++--- include/etl/pool.h | 6 +- include/etl/private/pvoidvector.h | 20 ++-- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 + test/test_binary.cpp | 152 +++++++++++++++--------------- 9 files changed, 111 insertions(+), 107 deletions(-) diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 760248fe..a5bdd2a0 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -59,7 +59,7 @@ namespace etl //************************************************************************* struct free_function : public etl::function { - free_function(void (*p_function_)(const etl::exception&)) + explicit free_function(void (*p_function_)(const etl::exception&)) : etl::function(p_function_) { } diff --git a/include/etl/function.h b/include/etl/function.h index 51843759..450aad77 100644 --- a/include/etl/function.h +++ b/include/etl/function.h @@ -112,7 +112,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()(TParameter data) const + void operator ()(TParameter data) const ETL_OVERRIDE { // Call the object's member function with the data. (p_object->*p_function)(data); @@ -148,7 +148,7 @@ namespace etl //************************************************************************* /// The function operator that calls the destination function. //************************************************************************* - virtual void operator ()() const + void operator ()() const ETL_OVERRIDE { // Call the object's member function. (p_object->*p_function)(); @@ -173,7 +173,7 @@ namespace etl /// Constructor. ///\param p_function Pointer to the function //************************************************************************* - function(void(*p_function_)(TParameter)) + explicit function(void(*p_function_)(TParameter)) : p_function(p_function_) { } @@ -182,7 +182,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()(TParameter data) const + void operator ()(TParameter data) const ETL_OVERRIDE { // Call the function with the data. (*p_function)(data); @@ -206,7 +206,7 @@ namespace etl /// Constructor. ///\param p_function Pointer to the function. //************************************************************************* - function(void(*p_function_)(void)) + explicit function(void(*p_function_)(void)) : p_function(p_function_) { } @@ -214,7 +214,7 @@ namespace etl //************************************************************************* /// The function operator that calls the destination function. //************************************************************************* - virtual void operator ()() const + void operator ()() const ETL_OVERRIDE { // Call the function. (*p_function)(); @@ -243,7 +243,7 @@ namespace etl /// Constructor. ///\param object Reference to the object //************************************************************************* - function_mp(TObject& object_) + explicit function_mp(TObject& object_) : p_object(&object_) { } @@ -252,7 +252,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()(TParameter data) const + void operator ()(TParameter data) const ETL_OVERRIDE { // Call the object's member function with the data. (p_object->*Function)(data); @@ -281,7 +281,7 @@ namespace etl /// Constructor. ///\param object Reference to the object //************************************************************************* - function_mv(TObject& object_) + explicit function_mv(TObject& object_) : p_object(&object_) { } @@ -290,7 +290,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()() const + void operator ()() const ETL_OVERRIDE { // Call the object's member function. (p_object->*Function)(); @@ -319,7 +319,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()(TParameter data) const + void operator ()(TParameter data) const ETL_OVERRIDE { // Call the object's member function with the data. (Instance.*Function)(data); @@ -344,7 +344,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()() const + void operator ()() const ETL_OVERRIDE { // Call the object's member function. (Instance.*Function)(); @@ -376,7 +376,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()(TParameter data) const + void operator ()(TParameter data) const ETL_OVERRIDE { // Call the object's member function with the data. (*Function)(data); @@ -408,7 +408,7 @@ namespace etl /// The function operator that calls the destination function. ///\param data The data to pass to the function. //************************************************************************* - virtual void operator ()() const + void operator ()() const ETL_OVERRIDE { // Call the function. (*Function)(); diff --git a/include/etl/pool.h b/include/etl/pool.h index cb191bb6..bb17bccb 100644 --- a/include/etl/pool.h +++ b/include/etl/pool.h @@ -623,9 +623,9 @@ namespace etl public: - static const size_t SIZE = base_t::SIZE; - static const size_t ALIGNMENT = base_t::ALIGNMENT; - static const size_t TYPE_SIZE = base_t::TYPE_SIZE; + using base_t::SIZE; + using base_t::ALIGNMENT; + using base_t::TYPE_SIZE; //************************************************************************* /// Constructor diff --git a/include/etl/private/pvoidvector.h b/include/etl/private/pvoidvector.h index 29ef41a0..789a0de9 100644 --- a/include/etl/private/pvoidvector.h +++ b/include/etl/private/pvoidvector.h @@ -224,7 +224,7 @@ namespace etl //********************************************************************* reference operator [](size_t i) { - return reference(p_buffer[i]); + return p_buffer[i]; } //********************************************************************* @@ -234,7 +234,7 @@ namespace etl //********************************************************************* const_reference operator [](size_t i) const { - return const_reference(p_buffer[i]); + return p_buffer[i]; } //********************************************************************* @@ -246,7 +246,7 @@ namespace etl reference at(size_t i) { ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); - return reference(p_buffer[i]); + return p_buffer[i]; } //********************************************************************* @@ -258,7 +258,7 @@ namespace etl const_reference at(size_t i) const { ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); - return const_reference(p_buffer[i]); + return p_buffer[i]; } //********************************************************************* @@ -267,7 +267,7 @@ namespace etl //********************************************************************* reference front() { - return reference(p_buffer[0]); + return p_buffer[0]; } //********************************************************************* @@ -276,7 +276,7 @@ namespace etl //********************************************************************* const_reference front() const { - return const_reference(p_buffer[0]); + return p_buffer[0]; } //********************************************************************* @@ -285,7 +285,7 @@ namespace etl //********************************************************************* reference back() { - return reference(*(p_end - 1)); + return *(p_end - 1); } //********************************************************************* @@ -294,7 +294,7 @@ namespace etl //********************************************************************* const_reference back() const { - return const_reference(*(p_end - 1)); + return *(p_end - 1); } //********************************************************************* @@ -303,7 +303,7 @@ namespace etl //********************************************************************* pointer data() { - return pointer(p_buffer); + return p_buffer; } //********************************************************************* @@ -312,7 +312,7 @@ namespace etl //********************************************************************* const_pointer data() const { - return const_pointer(p_buffer); + return p_buffer; } //********************************************************************* diff --git a/include/etl/version.h b/include/etl/version.h index b1f27f62..7823698f 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 16 -#define ETL_VERSION_PATCH 3 +#define ETL_VERSION_PATCH 4 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 43f5be9d..fb17ea08 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.16.3", + "version": "18.16.4", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 7e9fa6da..06d48732 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.16.3 +version=18.16.4 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 3e5bb0b5..b151dfdc 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.16.4 +Reduced warnings from cppcheck v2.2 + =============================================================================== 18.16.3 Added VS2019 to CI configuration file. diff --git a/test/test_binary.cpp b/test/test_binary.cpp index 88683a00..4ea6771d 100644 --- a/test/test_binary.cpp +++ b/test/test_binary.cpp @@ -38,84 +38,84 @@ SOFTWARE. #include "etl/integral_limits.h" #include "etl/type_traits.h" -// Count bits the easy way. -template -size_t test_count(T value) -{ - size_t count = 0; - - for (int i = 0; i < etl::integral_limits::bits; ++i) - { - if ((value & (T(1) << i)) != 0) - { - ++count; - } - } - - return count; -} - -// Check parity the easy way. -template -size_t test_parity(T value) -{ - size_t count = test_count(value); - - return count & 1; -} - -// Power of 2. -uint64_t test_power_of_2(int power) -{ - uint64_t result = 1; - - for (int i = 0; i < power; ++i) - { - result *= 2; - } - - return result; -} - -// Fold bits. -template -TReturn test_fold_bits(uint64_t value, int size) -{ - int bits_remaining = 64; - uint64_t mask = test_power_of_2(size) - 1; - TReturn result = 0; - - while (bits_remaining > size) - { - result = result ^ (value & mask); - value = value >> size; - bits_remaining -= size; - } - - result = result ^ (value & mask); - - return result; -} - -// Slow gray to binary -template -T compare_gray_to_binary(T value_) -{ - typedef typename std::make_unsigned::type type; - - type value = type(value_); - - T mask; - for (mask = value >> 1; mask != 0; mask = mask >> 1) - { - value = value ^ mask; - } - - return value; -} - namespace { + // Count bits the easy way. + template + size_t test_count(T value) + { + size_t count = 0; + + for (int i = 0; i < etl::integral_limits::bits; ++i) + { + if ((value & (T(1) << i)) != 0) + { + ++count; + } + } + + return count; + } + + // Check parity the easy way. + template + size_t test_parity(T value) + { + size_t count = test_count(value); + + return count & 1; + } + + // Power of 2. + uint64_t test_power_of_2(int power) + { + uint64_t result = 1; + + for (int i = 0; i < power; ++i) + { + result *= 2; + } + + return result; + } + + // Fold bits. + template + TReturn test_fold_bits(uint64_t value, int size) + { + int bits_remaining = 64; + uint64_t mask = test_power_of_2(size) - 1; + TReturn result = 0; + + while (bits_remaining > size) + { + result = result ^ (value & mask); + value = value >> size; + bits_remaining -= size; + } + + result = result ^ (value & mask); + + return result; + } + + // Slow gray to binary + template + T compare_gray_to_binary(T value_) + { + typedef typename std::make_unsigned::type type; + + type value = type(value_); + + T mask; + for (mask = value >> 1; mask != 0; mask = mask >> 1) + { + value = value ^ mask; + } + + return value; + } + SUITE(test_binary) { //*************************************************************************