Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-334

std::list::swap does not swap containers with different allocators correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.1.3
    • 4.2.0
    • 23. Containers
    • None
    • All

    Description

      The program below fails:

      ---------------------------------------------
      #include <list>
      #include <string>
      #include <cassert>

      class Alloc : public std::allocator <char>
      {
      };

      bool operator == (Alloc a1, Alloc a2)
      {
      return false;
      }

      bool operator != (Alloc a1, Alloc a2)
      {
      return true;
      }

      int main(int argc, char* argv[])
      {
      const char src [] = "source string";
      const char dst [] = "destination string";

      typedef std::list <char, Alloc> List;

      Alloc a1;
      Alloc a2;

      assert (!(a1 == a2));

      List src_lst (src, src + sizeof (src) - 1, a1);
      List dst_lst (dst, dst + sizeof (dst) - 1, a2);

      src_lst.swap (dst_lst);

      assert (std::string (src_lst.begin (), src_lst.end ()) == dst);
      assert (std::string (dst_lst.begin (), dst_lst.end ()) == src);

      return 0;
      }

      ---------------------------------------------

      Assertion failed: std::string (dst_lst.begin (), dst_lst.end ()) == src, file swap.cpp, line 37

      This application has requested the Runtime to terminate it in an unusual way.
      Please contact the application's support team for more information.

      Attachments

        Activity

          People

            farid Farid Zaripov
            farid Farid Zaripov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: