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++/61023] New: set/map move assignment doesn't move (or copy) the comparator


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

            Bug ID: 61023
           Summary: set/map move assignment doesn't move (or copy) the
                    comparator
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nevin at eviloverlord dot com

If you have a stateful comparator, set/map move assignment does not move (or
copy, for that matter) the comparator.

Test case:

struct Compare
{
    Compare(bool b) : b_(b) {}

    bool operator()(int l, int r) const
    { return b_ ? r < l : l < r; }

    bool b_; 
};

int main() 
{
    typedef std::set<int, Compare> S;

    S s(Compare(false));

    s.insert(2);
    s.insert(3);
    assert(*s.begin() == 2); 

    s.clear();
    S st(Compare(true));

    s = std::move(st); // move assignment

    s.insert(2);
    s.insert(3);
    assert(*s.begin() == 3); // fails

    return 0;
}


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