From 8089f74387b07072a19dadb5476391b2a1b63b5b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 1 Feb 2018 10:12:53 +0000 Subject: [PATCH 1/3] Added protected destructor to base class. --- src/debounce.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/debounce.h b/src/debounce.h index 19e26c20..3d3d78b3 100644 --- a/src/debounce.h +++ b/src/debounce.h @@ -99,7 +99,14 @@ namespace etl //************************************************************************* debounce_base(bool initial_state = false) : state(initial_state ? (CURRENT | LAST) : 0), - count(START_COUNT) + count(START_COUNT) + { + } + + //************************************************************************* + /// Destructor. + //************************************************************************* + ~debounce_base() { } From f9699d3cd494e5675827173859a06136fe10b624 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 1 Feb 2018 10:13:48 +0000 Subject: [PATCH 2/3] Added ETL_POLYMORPHIC_XXX defines --- test/etl_profile.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/etl_profile.h b/test/etl_profile.h index a321fa85..c4668ca7 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -39,6 +39,34 @@ SOFTWARE. #define ETL_IDEQUE_REPAIR_ENABLE #define ETL_IN_UNIT_TEST +#define ETL_POLYMORPHIC_BITSET +#define ETL_POLYMORPHIC_DEQUE +#define ETL_POLYMORPHIC_FLAT_MAP +#define ETL_POLYMORPHIC_FLAT_MULTIMAP +#define ETL_POLYMORPHIC_FLAT_SET +#define ETL_POLYMORPHIC_FLAT_MULTISET +#define ETL_POLYMORPHIC_FORWARD_LIST +#define ETL_POLYMORPHIC_LIST +#define ETL_POLYMORPHIC_MAP +#define ETL_POLYMORPHIC_MULTIMAP +#define ETL_POLYMORPHIC_SET +#define ETL_POLYMORPHIC_MULTISET +#define ETL_POLYMORPHIC_QUEUE +#define ETL_POLYMORPHIC_STACK +#define ETL_POLYMORPHIC_REFERENCE_FLAT_MAP +#define ETL_POLYMORPHIC_REFERENCE_FLAT_MULTIMAP +#define ETL_POLYMORPHIC_REFERENCE_FLAT_SET +#define ETL_POLYMORPHIC_REFERENCE_FLAT_MULTISET +#define ETL_POLYMORPHIC_UNORDERED_MAP +#define ETL_POLYMORPHIC_UNORDERED_MULTIMAP +#define ETL_POLYMORPHIC_UNORDERED_SET +#define ETL_POLYMORPHIC_UNORDERED_MULTISET +#define ETL_POLYMORPHIC_STRINGS +#define ETL_POLYMORPHIC_POOL +#define ETL_POLYMORPHIC_VECTOR + +//#define ETL_POLYMORPHIC_CONTAINERS + #ifdef _MSC_VER #include "profiles/msvc_x86.h" #else From 135506b53487fa126dd0b47c6312046cbd6a2d7c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 1 Feb 2018 10:15:51 +0000 Subject: [PATCH 3/3] Re-written to avoid 'undefined behavior' by allowing containers to be polymorphic or not base on a compile time macro. --- src/basic_string.h | 22 +++++++++++++++++++ src/bitset.h | 15 +++++++++++++ src/deque.h | 33 ++++++++++++++++++---------- src/flat_map.h | 26 ++++++++++++---------- src/flat_multimap.h | 26 ++++++++++++---------- src/flat_multiset.h | 26 ++++++++++++---------- src/flat_set.h | 26 ++++++++++++---------- src/forward_list.h | 33 ++++++++++++++++++---------- src/intrusive_forward_list.h | 7 ++++++ src/intrusive_list.h | 7 ++++++ src/intrusive_queue.h | 7 ++++++ src/intrusive_stack.h | 7 ++++++ src/list.h | 30 ++++++++++++++++---------- src/map.h | 33 ++++++++++++++++++---------- src/multimap.h | 35 +++++++++++++++++++----------- src/multiset.h | 35 +++++++++++++++++++----------- src/pool.h | 15 +++++++++++++ src/private/vector_base.h | 7 ++++++ src/queue.h | 34 +++++++++++++++++++---------- src/reference_flat_map.h | 15 +++++++++++++ src/reference_flat_multimap.h | 15 +++++++++++++ src/reference_flat_multiset.h | 15 +++++++++++++ src/reference_flat_set.h | 15 +++++++++++++ src/set.h | 37 +++++++++++++++++++++----------- src/stack.h | 33 ++++++++++++++++++---------- src/unordered_map.h | 26 ++++++++++++---------- src/unordered_multimap.h | 26 ++++++++++++---------- src/unordered_multiset.h | 26 ++++++++++++---------- src/unordered_set.h | 26 ++++++++++++---------- src/vector.h | 26 ++++++++++++---------- test/test_vector_non_trivial.cpp | 3 +++ 31 files changed, 485 insertions(+), 202 deletions(-) diff --git a/src/basic_string.h b/src/basic_string.h index 4fde9ebd..106803c6 100644 --- a/src/basic_string.h +++ b/src/basic_string.h @@ -235,6 +235,13 @@ namespace etl { } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~string_base() + { + } + bool is_truncated; ///< Set to true if the operation truncated the string. size_type current_size; ///< The current number of elements in the string. const size_type CAPACITY; ///< The maximum number of elements in the string. @@ -1970,6 +1977,21 @@ namespace etl ibasic_string(const ibasic_string&); T* p_buffer; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_STRINGS) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ibasic_string() + { + } +#else + protected: + ~ibasic_string() + { + } +#endif }; //*************************************************************************** diff --git a/src/bitset.h b/src/bitset.h index 584b97dc..bb61db38 100644 --- a/src/bitset.h +++ b/src/bitset.h @@ -718,6 +718,21 @@ namespace etl const size_t NBITS; const size_t SIZE; element_t* pdata; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_BITSET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ibitset() + { + } +#else + protected: + ~ibitset() + { + } +#endif }; //************************************************************************* diff --git a/src/deque.h b/src/deque.h index 014ee89c..0d0966cd 100644 --- a/src/deque.h +++ b/src/deque.h @@ -200,6 +200,13 @@ namespace etl { } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~deque_base() + { + } + size_type current_size; ///< The current number of elements in the deque. const size_type CAPACITY; ///< The maximum number of elements in the deque. const size_type BUFFER_SIZE; ///< The number of elements in the buffer. @@ -622,17 +629,6 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~ideque() - { - if (!empty()) - { - initialise(); - } - } - //************************************************************************* /// Assigns a range to the deque. //************************************************************************* @@ -1975,6 +1971,21 @@ namespace etl // Disable copy construction. ideque(const ideque&); + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_DEQUE) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ideque() + { + } +#else + protected: + ~ideque() + { + } +#endif }; //*************************************************************************** diff --git a/src/flat_map.h b/src/flat_map.h index cdd454b2..821e3baf 100644 --- a/src/flat_map.h +++ b/src/flat_map.h @@ -108,17 +108,6 @@ namespace etl public: - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iflat_map() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the flat_map. ///\return An iterator to the beginning of the flat_map. @@ -606,6 +595,21 @@ namespace etl /// Internal debugging. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_FLAT_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iflat_map() + { + } +#else + protected: + ~iflat_map() + { + } +#endif }; //*************************************************************************** diff --git a/src/flat_multimap.h b/src/flat_multimap.h index 4d143951..07f99def 100644 --- a/src/flat_multimap.h +++ b/src/flat_multimap.h @@ -110,17 +110,6 @@ namespace etl public: - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iflat_multimap() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the flat_multimap. ///\return An iterator to the beginning of the flat_multimap. @@ -557,6 +546,21 @@ namespace etl /// Internal debugging. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_FLAT_MULTIMAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iflat_multimap() + { + } +#else + protected: + ~iflat_multimap() + { + } +#endif }; //*************************************************************************** diff --git a/src/flat_multiset.h b/src/flat_multiset.h index 5c378a3c..6d4a05a3 100644 --- a/src/flat_multiset.h +++ b/src/flat_multiset.h @@ -86,17 +86,6 @@ namespace etl public: - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iflat_multiset() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the flat_multiset. ///\return An iterator to the beginning of the flat_multiset. @@ -535,6 +524,21 @@ namespace etl /// Internal debugging. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_FLAT_MULTISET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iflat_multiset() + { + } +#else + protected: + ~iflat_multiset() + { + } +#endif }; //*************************************************************************** diff --git a/src/flat_set.h b/src/flat_set.h index adb2de9f..0b5f17f0 100644 --- a/src/flat_set.h +++ b/src/flat_set.h @@ -86,17 +86,6 @@ namespace etl public: - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iflat_set() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the flat_set. ///\return An iterator to the beginning of the flat_set. @@ -540,6 +529,21 @@ namespace etl /// Internal debugging. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_FLAT_SET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iflat_set() + { + } +#else + protected: + ~iflat_set() + { + } +#endif }; //*************************************************************************** diff --git a/src/forward_list.h b/src/forward_list.h index 23fa7b3f..e9a2fc08 100644 --- a/src/forward_list.h +++ b/src/forward_list.h @@ -222,6 +222,13 @@ namespace etl { } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~forward_list_base() + { + } + //************************************************************************* /// Get the head node. //************************************************************************* @@ -477,17 +484,6 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iforward_list() - { - if (!empty()) - { - clear(); - } - } - //************************************************************************* /// Gets the beginning of the forward_list. //************************************************************************* @@ -1343,6 +1339,21 @@ namespace etl // Disable copy construction. iforward_list(const iforward_list&); + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_FORWARD_LIST) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iforward_list() + { + } +#else + protected: + ~iforward_list() + { + } +#endif }; //************************************************************************* diff --git a/src/intrusive_forward_list.h b/src/intrusive_forward_list.h index c2d91d2b..1ac767dd 100644 --- a/src/intrusive_forward_list.h +++ b/src/intrusive_forward_list.h @@ -237,6 +237,13 @@ namespace etl size_t current_size; ///< Counts the number of elements in the list. + //************************************************************************* + /// Destructor + //************************************************************************* + ~intrusive_forward_list_base() + { + } + //************************************************************************* /// Is the intrusive_forward_list a trivial length? //************************************************************************* diff --git a/src/intrusive_list.h b/src/intrusive_list.h index a3d3be91..e78a2669 100644 --- a/src/intrusive_list.h +++ b/src/intrusive_list.h @@ -242,6 +242,13 @@ namespace etl size_t current_size; ///< Counts the number of elements in the list. + //************************************************************************* + /// Destructor + //************************************************************************* + ~intrusive_list_base() + { + } + //************************************************************************* /// Is the intrusive_list a trivial length? //************************************************************************* diff --git a/src/intrusive_queue.h b/src/intrusive_queue.h index bc3edc71..315e25ee 100644 --- a/src/intrusive_queue.h +++ b/src/intrusive_queue.h @@ -181,6 +181,13 @@ namespace etl { } + //************************************************************************* + /// Destructor + //************************************************************************* + ~intrusive_queue_base() + { + } + link_type* p_front; ///< The current front of the queue. link_type* p_back; ///< The current back of the queue. diff --git a/src/intrusive_stack.h b/src/intrusive_stack.h index 020ca3a0..9ead1175 100644 --- a/src/intrusive_stack.h +++ b/src/intrusive_stack.h @@ -188,6 +188,13 @@ namespace etl { } + //************************************************************************* + /// Destructor + //************************************************************************* + ~intrusive_stack_base() + { + } + link_type* p_top; ///< The current top of the stack. size_t current_size; ///< Counts the number of elements in the list. diff --git a/src/list.h b/src/list.h index f373fd29..65f9efc0 100644 --- a/src/list.h +++ b/src/list.h @@ -306,6 +306,13 @@ namespace etl { } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~list_base() + { + } + etl::ipool* p_node_pool; ///< The pool of data nodes used in the list. node_t terminal_node; ///< The node that acts as the list start and end. const size_type MAX_SIZE; ///< The maximum size of the list. @@ -583,17 +590,6 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~ilist() - { - if (!empty()) - { - initialise(); - } - } - //************************************************************************* /// Gets the beginning of the list. //************************************************************************* @@ -1566,6 +1562,18 @@ namespace etl // Disable copy construction. ilist(const ilist&); + +#if defined(ETL_POLYMORPHIC_LIST) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ilist() + { + } +#else + protected: + ~ilist() + { + } +#endif }; //************************************************************************* diff --git a/src/map.h b/src/map.h index 4c1dea50..61695cec 100644 --- a/src/map.h +++ b/src/map.h @@ -233,6 +233,13 @@ namespace etl { } + //************************************************************************* + /// Destructor + //************************************************************************* + ~map_base() + { + } + //************************************************************************* /// Balance the critical node at the position provided as needed //************************************************************************* @@ -801,17 +808,6 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~imap() - { - if (!empty()) - { - clear(); - } - } - //************************************************************************* /// Gets the beginning of the map. //************************************************************************* @@ -2007,6 +2003,21 @@ namespace etl // Disable copy construction. imap(const imap&); + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~imap() + { + } +#else + protected: + ~imap() + { + } +#endif }; //************************************************************************* diff --git a/src/multimap.h b/src/multimap.h index 4139c264..b5a5a897 100644 --- a/src/multimap.h +++ b/src/multimap.h @@ -224,7 +224,13 @@ namespace etl : current_size(0) , CAPACITY(max_size_) , root_node(nullptr) - + { + } + + //************************************************************************* + /// The constructor that is called from derived classes. + //************************************************************************* + ~multimap_base() { } @@ -952,17 +958,6 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~imultimap() - { - if (!empty()) - { - clear(); - } - } - //************************************************************************* /// Gets the beginning of the multimap. //************************************************************************* @@ -1892,6 +1887,22 @@ namespace etl // Disable copy construction. imultimap(const imultimap&); + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_MULTIMAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~imultimap() + { + } +#else + protected: + ~imultimap() + { + } +#endif + }; //************************************************************************* diff --git a/src/multiset.h b/src/multiset.h index 23e265ba..abdfd2e5 100644 --- a/src/multiset.h +++ b/src/multiset.h @@ -226,7 +226,14 @@ namespace etl , root_node(nullptr) { } - + + //************************************************************************* + /// Destructor. + //************************************************************************* + ~multiset_base() + { + } + //************************************************************************* /// Attach the provided node to the position provided //************************************************************************* @@ -932,17 +939,6 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~imultiset() - { - if (!empty()) - { - clear(); - } - } - //************************************************************************* /// Gets the beginning of the multiset. //************************************************************************* @@ -1872,6 +1868,21 @@ namespace etl // Disable copy construction. imultiset(const imultiset&); + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_MULTISET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~imultiset() + { + } +#else + protected: + ~imultiset() + { + } +#endif }; //************************************************************************* diff --git a/src/pool.h b/src/pool.h index a945767a..01ff1a13 100644 --- a/src/pool.h +++ b/src/pool.h @@ -321,6 +321,21 @@ namespace etl const uint32_t ITEM_SIZE; ///< The size of allocated items. const uint32_t MAX_SIZE; ///< The maximum number of objects that can be allocated. + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_POOL) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ipool() + { + } +#else + protected: + ~ipool() + { + } +#endif }; //************************************************************************* diff --git a/src/private/vector_base.h b/src/private/vector_base.h index 732ec657..bcd131ab 100644 --- a/src/private/vector_base.h +++ b/src/private/vector_base.h @@ -154,6 +154,13 @@ namespace etl { } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~vector_base() + { + } + const size_type CAPACITY; /// /// \return A reference to the value at the front of the queue. @@ -485,6 +482,21 @@ namespace etl iqueue(const iqueue&); T* p_buffer; ///< The internal buffer. + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_QUEUE) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iqueue() + { + } +#else + protected: + ~iqueue() + { + } +#endif }; //*************************************************************************** diff --git a/src/reference_flat_map.h b/src/reference_flat_map.h index bfd66da4..0963e77f 100644 --- a/src/reference_flat_map.h +++ b/src/reference_flat_map.h @@ -854,6 +854,21 @@ namespace etl ireference_flat_map& operator = (const ireference_flat_map&); lookup_t& lookup; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_REFERENCE_FLAT_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ireference_flat_map() + { + } +#else + protected: + ~ireference_flat_map() + { + } +#endif }; //*************************************************************************** diff --git a/src/reference_flat_multimap.h b/src/reference_flat_multimap.h index 6076596d..1b428e11 100644 --- a/src/reference_flat_multimap.h +++ b/src/reference_flat_multimap.h @@ -767,6 +767,21 @@ namespace etl ireference_flat_multimap& operator = (const ireference_flat_multimap&); lookup_t& lookup; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_REFERENCE_FLAT_MULTIMAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ireference_flat_multimap() + { + } +#else + protected: + ~ireference_flat_multimap() + { + } +#endif }; //*************************************************************************** diff --git a/src/reference_flat_multiset.h b/src/reference_flat_multiset.h index d0a2cd53..bd72dc1e 100644 --- a/src/reference_flat_multiset.h +++ b/src/reference_flat_multiset.h @@ -780,6 +780,21 @@ namespace etl ireference_flat_multiset& operator =(const ireference_flat_multiset&); lookup_t& lookup; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_REFERENCE_FLAT_MULTISET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ireference_flat_multiset() + { + } +#else + protected: + ~ireference_flat_multiset() + { + } +#endif }; //*************************************************************************** diff --git a/src/reference_flat_set.h b/src/reference_flat_set.h index ef9f6089..3f4f7cb5 100644 --- a/src/reference_flat_set.h +++ b/src/reference_flat_set.h @@ -762,6 +762,21 @@ namespace etl ireference_flat_set& operator =(const ireference_flat_set&); lookup_t& lookup; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_REFERENCE_FLAT_SET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ireference_flat_set() + { + } +#else + protected: + ~ireference_flat_set() + { + } +#endif }; //*************************************************************************** diff --git a/src/set.h b/src/set.h index be0407c4..a3040c57 100644 --- a/src/set.h +++ b/src/set.h @@ -227,6 +227,13 @@ namespace etl { } + //************************************************************************* + /// The constructor that is called from derived classes. + //************************************************************************* + ~set_base() + { + } + //************************************************************************* /// Attach the provided node to the position provided //************************************************************************* @@ -437,6 +444,7 @@ namespace etl const size_type CAPACITY; ///< The maximum size of the set. Node* root_node; ///< The node that acts as the set root. etl::debug_count construct_count; + }; //*************************************************************************** @@ -771,8 +779,7 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - - + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -786,17 +793,6 @@ namespace etl return *this; } - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iset() - { - if (!empty()) - { - clear(); - } - } - //************************************************************************* /// Gets the beginning of the set. //************************************************************************* @@ -1930,6 +1926,21 @@ namespace etl // Disable copy construction. iset(const iset&); + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_SET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iset() + { + } +#else + protected: + ~iset() + { + } +#endif }; //************************************************************************* diff --git a/src/stack.h b/src/stack.h index 3bca539e..e4a36702 100644 --- a/src/stack.h +++ b/src/stack.h @@ -165,6 +165,13 @@ namespace etl { } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~stack_base() + { + } + //************************************************************************* /// Increments the indexes value to record a stack addition. //************************************************************************* @@ -230,17 +237,6 @@ namespace etl public: - //************************************************************************* - /// Destructor. - //************************************************************************* - ~istack() - { - if (!empty()) - { - clear(); - } - } - //************************************************************************* /// Gets a reference to the value at the top of the stack.
/// \return A reference to the value at the top of the stack. @@ -454,6 +450,21 @@ namespace etl istack(const istack&); T* p_buffer; ///< The internal buffer. + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_STACK) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~istack() + { + } +#else + protected: + ~istack() + { + } +#endif }; //*************************************************************************** diff --git a/src/unordered_map.h b/src/unordered_map.h index d90304a1..c1d4d331 100644 --- a/src/unordered_map.h +++ b/src/unordered_map.h @@ -480,17 +480,6 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iunordered_map() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the unordered_map. ///\return An iterator to the beginning of the unordered_map. @@ -1294,6 +1283,21 @@ namespace etl /// For library debugging purposes only. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_UNORDERED_MAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iunordered_map() + { + } +#else + protected: + ~iunordered_map() + { + } +#endif }; //*************************************************************************** diff --git a/src/unordered_multimap.h b/src/unordered_multimap.h index a8a8a969..ea8c5792 100644 --- a/src/unordered_multimap.h +++ b/src/unordered_multimap.h @@ -480,17 +480,6 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iunordered_multimap() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the unordered_multimap. ///\return An iterator to the beginning of the unordered_multimap. @@ -1204,6 +1193,21 @@ namespace etl /// For library debugging purposes only. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_UNORDERED_MULTIMAP) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iunordered_multimap() + { + } +#else + protected: + ~iunordered_multimap() + { + } +#endif }; //*************************************************************************** diff --git a/src/unordered_multiset.h b/src/unordered_multiset.h index b42d3e4f..829849da 100644 --- a/src/unordered_multiset.h +++ b/src/unordered_multiset.h @@ -475,17 +475,6 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iunordered_multiset() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the unordered_multiset. ///\return An iterator to the beginning of the unordered_multiset. @@ -1198,6 +1187,21 @@ namespace etl /// For library debugging purposes only. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_UNORDERED_MULTISET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iunordered_multiset() + { + } +#else + protected: + ~iunordered_multiset() + { + } +#endif }; //*************************************************************************** diff --git a/src/unordered_set.h b/src/unordered_set.h index d8d6087d..5cf2bc86 100644 --- a/src/unordered_set.h +++ b/src/unordered_set.h @@ -476,17 +476,6 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; - //************************************************************************* - /// Destructor. - //************************************************************************* - ~iunordered_set() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the unordered_set. ///\return An iterator to the beginning of the unordered_set. @@ -1175,6 +1164,21 @@ namespace etl /// For library debugging purposes only. etl::debug_count construct_count; + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_UNORDERED_SET) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~iunordered_set() + { + } +#else + protected: + ~iunordered_set() + { + } +#endif }; //*************************************************************************** diff --git a/src/vector.h b/src/vector.h index 2cc369df..bbc8b820 100644 --- a/src/vector.h +++ b/src/vector.h @@ -93,17 +93,6 @@ namespace etl public: - //************************************************************************* - /// Destructor. - //************************************************************************* - ~ivector() - { - if (!empty()) - { - clear(); - } - } - //********************************************************************* /// Returns an iterator to the beginning of the vector. ///\return An iterator to the beginning of the vector. @@ -968,6 +957,21 @@ namespace etl // Disable copy construction. ivector(const ivector&); + + //************************************************************************* + /// Destructor. + //************************************************************************* +#if defined(ETL_POLYMORPHIC_VECTOR) || defined(ETL_POLYMORPHIC_CONTAINERS) + public: + virtual ~ivector() + { + } +#else + protected: + ~ivector() + { + } +#endif }; //*************************************************************************** diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index c7c00a8b..88c1e7f4 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -99,6 +99,9 @@ namespace int current_count = NDC::get_instance_count(); + DataNDC* p = new DataNDC(INITIAL_SIZE, INITIAL_VALUE); + delete p; + DataNDC* pdata = new DataNDC(INITIAL_SIZE, INITIAL_VALUE); CHECK_EQUAL(int(current_count + INITIAL_SIZE), NDC::get_instance_count());