title: std::set::erase unexpectedly erases 3 elements
body: <p>Before the last <code>erase</code>, the elements in the <code>s1</code> and <code>s2</code> are the same.</p>
  <p>The last <code>erase</code> to the <code>s1</code> erases 1 element in the set <code>s1</code>. It is correct.</p>
  <p>The last <code>erase</code> to the <code>s2</code> erases 3 elements in the set <code>s2</code>. It is unexpected.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;cassert&gt;
  #include &lt;set&gt;
  #include &lt;functional&gt;
  
  using namespace std;
  
  struct Ev {
    int p = 0;
    int l = 0;
    int r = 0;
    bool open = false;
  
    friend ostream&amp; operator&lt;&lt;(ostream&amp; os, const Ev&amp; ev);
  };
  
  ostream&amp; operator&lt;&lt;(ostream&amp; os, const Ev&amp; ev) {
    os &lt;&lt; &quot;p = &quot; &lt;&lt; ev.p &lt;&lt; &quot;, l = &quot; &lt;&lt; ev.l &lt;&lt; &quot;, r = &quot; &lt;&lt; ev.r &lt;&lt; boolalpha
       &lt;&lt; &quot;, open = &quot; &lt;&lt; ev.open;
    return os;
  }
  
  int main() {
    auto lr_cmp = [](const Ev&amp; lhs, const Ev&amp; rhs) {
      return lhs.r == rhs.l;
    };
    set&lt;Ev, decltype(lr_cmp)&gt; s1(lr_cmp);
    set&lt;Ev, decltype(lr_cmp)&gt; s2(lr_cmp);
  
    assert(s1.insert({0, 0, 1, true}).second);
    assert(s1.insert({1, 1, 3, true}).second);
    assert(s1.insert({2, 3, 4, true}).second);
    assert(s1.insert({0, 4, 5, true}).second);
    for (const auto&amp; ev : s1) {
      cout &lt;&lt; ev &lt;&lt; endl;
    }
    assert(s1.erase({3, 1, 3, false}) == 1);
    
    cout &lt;&lt; &quot;--------------------------------&quot; &lt;&lt; endl;
  
    assert(s2.insert({1, 1, 3, true}).second);
    assert(s2.insert({1, 3, 4, true}).second);
    assert(s2.insert({0, 0, 1, true}).second);
    assert(s2.insert({0, 4, 5, true}).second);
    assert(s2.erase({2, 3, 4, false}) == 1);
    assert(s2.insert({2, 3, 4, true}).second);
    for (const auto&amp; ev : s2) {
      cout &lt;&lt; ev &lt;&lt; endl;
    }
    assert(s2.erase({3, 1, 3, false}) == 1);
    return 0;
  }
  </code></pre>
  <p>Here is the output.</p>
  <pre><code>p = 0, l = 0, r = 1, open = true
  p = 1, l = 1, r = 3, open = true
  p = 2, l = 3, r = 4, open = true
  p = 0, l = 4, r = 5, open = true
  --------------------------------
  p = 0, l = 0, r = 1, open = true
  p = 1, l = 1, r = 3, open = true
  p = 2, l = 3, r = 4, open = true
  p = 0, l = 4, r = 5, open = true
  prog.exe: prog.cc:51: int main(): Assertion `s2.erase({3, 1, 3, false}) == 1' failed.
  Aborted
  </code></pre>