[Bug middle-end/90923] hash_map destroys elements without constructing them

2019-07-01 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90923

Martin Sebor  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED
   Target Milestone|--- |10.0

--- Comment #4 from Martin Sebor  ---
Committed in r272893.

[Bug middle-end/90923] hash_map destroys elements without constructing them

2019-07-01 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90923

--- Comment #3 from Martin Sebor  ---
Author: msebor
Date: Mon Jul  1 18:33:36 2019
New Revision: 272893

URL: https://gcc.gnu.org/viewcvs?rev=272893&root=gcc&view=rev
Log:
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.


Modified:
trunk/gcc/ChangeLog
trunk/gcc/hash-map-tests.c
trunk/gcc/hash-map.h
trunk/gcc/hash-set-tests.c
trunk/gcc/hash-set.h
trunk/gcc/hash-table.h

[Bug middle-end/90923] hash_map destroys elements without constructing them

2019-06-18 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90923

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch
 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2019-06-19
   Assignee|unassigned at gcc dot gnu.org  |msebor at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #2 from Martin Sebor  ---
Patch: https://gcc.gnu.org/ml/gcc-patches/2019-06/msg01105.html

[Bug middle-end/90923] hash_map destroys elements without constructing them

2019-06-18 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90923

Martin Sebor  changed:

   What|Removed |Added

   Keywords||wrong-code
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=90904

--- Comment #1 from Martin Sebor  ---
The otherwise untested patch is enough to fix the test case:

diff --git a/gcc/hash-map.h b/gcc/hash-map.h
index 588dfda04fa..40e5ec5871e 100644
--- a/gcc/hash-map.h
+++ b/gcc/hash-map.h
@@ -177,7 +177,10 @@ public:
   INSERT);
   bool ins = Traits::is_empty (*e);
   if (ins)
-   e->m_key = k;
+   {
+ e->m_key = k;
+ new ((void *)&e->m_value) Value ();
+   }

   if (existed != NULL)
*existed = !ins;