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

            Bug ID: 84056
           Summary: map insertes a pair when check a value
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: alper.ccc at yandex dot com
  Target Milestone: ---

In this example there is a map with 2 pairs ( a:1 and b:2)
but after checking the unavailable vale in if statement (value of c) it inserts
new pair (c:0) to the map:


#include <iostream>
#include <map>
using namespace std;
int main ()
{
  map<char,int> my_map;
  my_map['a'] = 1;
  my_map['b'] = 2;

  for (map<char,int>::iterator it=my_map.begin(); it!=my_map.end(); ++it)
    cout << it->first << " => " << it->second << endl;

  if(my_map['c'] == 100)
          cout<<"my_map['c'] = 100"<<endl; // do something

  cout<<"Map after if condition(a new pair ['c':0] inserted in map!):"<<endl;
  for (map<char,int>::iterator it=my_map.begin(); it!=my_map.end(); ++it)
    cout << it->first << " => " << it->second << endl;

  return 0;
}

Reply via email to