https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92300

            Bug ID: 92300
           Summary: Useless allocator call in std::map, when insert does
                    not perform any insertion.
           Product: gcc
           Version: 7.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: antonio.di.monaco at sap dot com
  Target Milestone: ---

Created attachment 47142
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47142&action=edit
code example

The fix related to the bug 78595 introduced a regression in the std::map insert
call.

When a key already exists, an allocation is performed anyway.

std::map< int, int, std::less< int >, MyAlloc< std::pair< const int, int > > >
a;

assert(a.insert(std::make_pair(1, 1)).second);
assert(a.insert(std::make_pair(2, 2)).second);
assert(!a.insert(std::make_pair(1, 3)).second);

GCC 6:

map:
allocate 1 element(s) of size 40
 allocated at: 0x13d8c20
allocate 1 element(s) of size 40
 allocated at: 0x13d8c50

GCC >= 7.4.0:

map:
allocate 1 element(s) of size 40
 allocated at: 0x14f1c20
allocate 1 element(s) of size 40
 allocated at: 0x14f1c50
allocate 1 element(s) of size 40
 allocated at: 0x14f1c80

Other associative containers have not been affected by the change.

Reply via email to