[Bug libstdc++/47628] non-compliant C++0x erase methods on STL containers

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Feb 7 17:23:00 GMT 2011


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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-02-07 17:17:54 UTC ---
Here's a reduced form of the code, which works with GCC 4.5 and earlier, but is
ambiguous with 4.6

#include <map>

struct Key
{
    Key() { }

    Key(const Key&) { }

    template<typename T>
        Key(const T&)
        { }

    bool operator<(const Key&) const;
};

typedef std::map<Key, int> Map;

void f()
{
    Map m;
    (void) m[Key()];
    Map::iterator i = m.begin();
    m.erase(i);
}

I'm not sure if the code is valid or not (Paolo?)

In C++0x mode the ambiguity is in the user code, because non-const iterator can
be converted to const_iterator or key_type (I believe this behaviour is
required by the standard)

In C++98 mode it's in the library code when calling _M_t.erase - this is a
regression.  Paolo, should _Rb_tree::erase take a non-const iterator in c++98
mode?  That's what map::erase passes it.



More information about the Gcc-bugs mailing list