<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - hash_map::insert does not accept convertible-to-value_type"
href="http://llvm.org/bugs/show_bug.cgi?id=22510">22510</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>hash_map::insert does not accept convertible-to-value_type
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>eugeni.stepanov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>#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;
^</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>