According to ISO/IEC 14882:1998 25.2.2 std::swap_ranges must call std::swap.
This can be tested because std::swap is overloaded for std::vector. The
following program fails:


#include <algorithm>
#include <cassert>
#include <vector>

bool copy_allowed = true;

struct Foo
{
    Foo() { }
    Foo(const Foo&) { assert(copy_allowed); }
    Foo& operator=(const Foo&) { assert(copy_allowed); return *this; }
};

int main()
{
    std::vector<Foo> foo[2];
    foo[0].push_back(Foo());
    copy_allowed = false;
    std::swap_ranges(foo, foo + 1, foo + 1);
    copy_allowed = true;
}


/tmp > g++-3.4 -Wall swap.cpp -o swap
/tmp > ./swap 
swap: swap.cpp:10: Foo::Foo(const Foo&): Assertion `copy_allowed' failed.
Aborted


There is the same problem with most algorithms that must call std::swap, e.g.
std::sort, std::reverse, std::rotate, ...


/tmp > g++-3.4 --version
g++-3.4 (GCC) 3.4.4 20050314 (prerelease) (Debian 3.4.3-13)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-- 
           Summary: swap_ranges must call swap instead of iter_swap
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: h dot schmid at gmx dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21830

Reply via email to