title: crash for C++ map when deleting via iterator
body: <p>I have the following code which crashes</p>
  <pre><code>#include &lt;map&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
          map&lt;int,int&gt; m;
          m[1]=2;
          m[2]=3;
          m[3]=4;
          m[4]=5;
          /*
          m.insert(std::make_pair(1,2));
          m.insert(std::make_pair(2,3));
          m.insert(std::make_pair(3,4));
          m.insert(std::make_pair(4,5));
          */
          for (auto it=m.begin();it!=m.end();)
          {
                  cout &lt;&lt; it-&gt;first &lt;&lt; &quot;-&gt;&quot; &lt;&lt; it-&gt;second &lt;&lt; endl;
                  if (it-&gt;first == 3) {
                          auto next = ++it; // &lt;------------------------
                          m.erase(it);
                          cout &lt;&lt; &quot;Restart &quot; &lt;&lt; endl;
                          it = m.begin();
                  }
                  else
                  {
                          ++it;
                  }
          }
  
          return 0;
  }
  </code></pre>
  <p>The problem dissapears if I comment the line with &lt;------------------ and I cannot explain myself why.</p>
  <p>Any clues?</p>