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

            Bug ID: 118035
           Summary: deque<string> bug when inserting an empty iterator
                    interval
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: p2ye at uwaterloo dot ca
  Target Milestone: ---

Created attachment 59861
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59861&action=edit
demonstration of the bug

In the following code, I insert an empty iterator range [v.begin(), v.end())
into my_deque and then I output each element of the deque:

#include <deque>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  deque<string> my_deque{"one", "two", "three"};
  vector<string> v{};
  my_deque.insert(my_deque.begin() + 1, v.begin(), v.end());
  for (auto s : my_deque) {
    cout << s << endl;
  }
}

I would expect the output to be "one\ntwo\nthree\n", since inserting an empty
range into the deque should not modify the deque.

However, the output that I get is "one\n\n\n", which shows that the insert
operation somehow cleared the strings "two" and "three".

Reply via email to