diff options
author | Martin Sebor <msebor@redhat.com> | 2019-07-01 18:33:36 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-07-01 12:33:36 -0600 |
commit | 7b8795a138d0baa3b0505baee2ed05ae266977cd (patch) | |
tree | 74e86b5944db91f0d3068ed61906a8a389b0cf42 /gcc/hash-set.h | |
parent | 25cd9afbc1dc6bd9d4afccab3f09f0fbc811291a (diff) | |
download | gcc-7b8795a138d0baa3b0505baee2ed05ae266977cd.tar.gz |
PR middle-end/90923 - hash_map destroys elements without constructing them
gcc/ChangeLog:
PR middle-end/90923
* hash-map.h (hash_map::put): On insertion invoke element ctor.
(hash_map::get_or_insert): Same. Reformat comment.
* hash-set.h (hash_set::add): On insertion invoke element ctor.
* hash-map-tests.c (test_map_of_type_with_ctor_and_dtor): New.
* hash-set-tests.c (test_map_of_type_with_ctor_and_dtor): New.
* hash-table.h (hash_table::operator=): Prevent copy assignment.
(hash_table::hash_table (const hash_table&)): Use copy ctor
instead of assignment to copy elements.
From-SVN: r272893
Diffstat (limited to 'gcc/hash-set.h')
-rw-r--r-- | gcc/hash-set.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/gcc/hash-set.h b/gcc/hash-set.h index d891ed78297..a79a88d1ab9 100644 --- a/gcc/hash-set.h +++ b/gcc/hash-set.h @@ -21,6 +21,16 @@ along with GCC; see the file COPYING3. If not see #ifndef hash_set_h #define hash_set_h +/* Class hash_set is a hash-value based container for objects of + KeyId type. + KeyId may be a non-trivial (non-POD) type provided a suitabe Traits + class. Default Traits specializations are provided for basic types + such as integers, pointers, and std::pair. Inserted elements are + value-initialized either to zero for POD types or by invoking their + default ctor. Removed elements are destroyed by invoking their dtor. + On hash_set destruction all elements are removed. Objects of + hash_set type are copy-constructible but not assignable. */ + template<typename KeyId, bool Lazy = false, typename Traits = default_hash_traits<KeyId> > class hash_set @@ -48,7 +58,7 @@ public: Key *e = m_table.find_slot_with_hash (k, Traits::hash (k), INSERT); bool existed = !Traits::is_empty (*e); if (!existed) - *e = k; + new (e) Key (k); return existed; } |