This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/69081] New: forward_list::splice_after does not handle the case of first<=last properly


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

            Bug ID: 69081
           Summary: forward_list::splice_after does not handle the case of
                    first<=last properly
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wli2008ms at outlook dot com
  Target Milestone: ---

In this API,

void splice_after( const_iterator pos, forward_list& other,
                   const_iterator first, const_iterator last )

It supposes to transfer elements [first, last).  If the last is before the
first, then [first, last) shall be empty set mathematically.  So, the list of
pos shall not be touched.  However, with the current implementation, the list
of pos is left undefined after the call in such case.

--

#include <iostream>
#include <forward_list>

int main()
{
    std::forward_list<int> l1 = {1,2,3,4,5};
    std::forward_list<int> l2 = {10,11,12};

    l2.splice_after(l2.cbefore_begin(), l1, l1.cbegin(), l1.cbegin());

    for(int n : l1)
        std::cout << n << ' ';
    std::cout << '\n';

    for(int n : l2)
        std::cout << n << ' ';
    std::cout << '\n';
}

Output:

1 

2 3 4 5

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]