[Bug libstdc++/56112] New: [4.8 Regression] cannot create unordered_map from range of types convertible to value_type

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jan 25 19:15:00 GMT 2013


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

             Bug #: 56112
           Summary: [4.8 Regression] cannot create unordered_map from
                    range of types convertible to value_type
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: redi@gcc.gnu.org


#include <unordered_map>

struct S
{
    operator std::pair<const int, int>() const { return {}; }
};

int main()
{
    S s[1];
    std::unordered_map<int, int> m(s, s+1);   // error

    std::pair<const int, int> p = *s;  // OK
    m.insert(s, s+1);  // OK
}


This is valid (value_type is EmplaceConstructible into the container from s[0])
but it fails to compile because of the change to use std::__detail::_Select1st
instead of std::_Select1st<value_type>

The template argument for _Select1st::operator() cannot be deduced from the
object of type S. The problem boils down to this:

#include <utility>

struct S
{
    operator std::pair<const int, int>() const { return {}; }
};

void f()
{
    S s;
    std::get<0>(s);
}

This is not valid, but the range constructors of unordered_map and
unordered_multimap assume using std::get<0> on the iterator's value type will
work, which is not a valid assumption.



More information about the Gcc-bugs mailing list