[LLVMbugs] [Bug 22510] New: hash_map::insert does not accept convertible-to-value_type

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Feb 8 16:26:59 PST 2015


http://llvm.org/bugs/show_bug.cgi?id=22510

            Bug ID: 22510
           Summary: hash_map::insert does not accept
                    convertible-to-value_type
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eugeni.stepanov at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

#include <ext/hash_map>

using __gnu_cxx::hash_map;

template<typename T>
class Wrap {
  T t;
public:
  Wrap(T t) : t(t) {}
  operator T() { return t; }
};

void f() {
  hash_map<int, int> h;
  Wrap<hash_map<int, int>::value_type> w(std::pair<int, int>(1, 2));
  h.insert(&w, &w + 1);
// h.insert(w);
}


The error boils down to hash_map trying to copy the inserted value into
pair<key, value>, which value_type (aka pair<const key, value>) is convertible
to, but the above Wrap class is not (double conversion).

Note that inserting the element directly (see the commented line) works.

Snippets from the error message follow.

include/c++/v1/memory:1645:31: error: no matching constructor for
initialization of 'std::__1::pair<int, int>'
            ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);

...

include/c++/v1/utility:281:5: note: candidate constructor not viable: no known
conversion from 'Wrap<std::__1::pair<const int, int> >' to 'const
std::__1::pair<int, int>' for 1st argument
    pair(const pair& __p) = default;
/code/llvm/build/bin/../include/c++/v1/utility:324:5: note: candidate
constructor not viable: no known conversion from 'Wrap<std::__1::pair<const
int, int> >' to 'std::__1::pair<int, int>' for 1st argument
    pair(pair&& __p) = default;
    ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150209/cf77303b/attachment.html>


More information about the llvm-bugs mailing list