[LLVMbugs] [Bug 6898] New: Want better diagnostic for missing std::hash<T> specialization
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Apr 22 18:43:19 PDT 2010
http://llvm.org/bugs/show_bug.cgi?id=6898
Summary: Want better diagnostic for missing std::hash<T>
specialization
Product: clang
Version: trunk
Platform: PC
OS/Version: All
Status: NEW
Keywords: quality-of-implementation
Severity: enhancement
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: jyasskin at google.com
CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com
$ cat test.cc
#include <ext/hash_set>
#include <string>
void foo() {
__gnu_cxx::hash_set<std::string> hs;
hs.insert("Hello world");
}
$ clang++ -c test.cc
In file included from test.cc:1:
In file included from /usr/include/c++/4.0.0/ext/hash_set:64:
/usr/include/c++/4.0.0/ext/hashtable.h:596:16: error: type 'hasher const' (aka
'__gnu_cxx::hash<std::basic_string<char> > const') does not provide a call
operator
{ return _M_hash(__key) % __n; }
^~~~~~~
/usr/include/c++/4.0.0/ext/hashtable.h:600:16: note: in instantiation of member
function '__gnu_cxx::hashtable<std::basic_string<char>,
std::basic_string<char>, __gnu_cxx::hash<std::basic_string<char> >,
std::_Identity<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
> >::_M_bkt_num_key' requested here
{ return _M_bkt_num_key(_M_get_key(__obj), __n); }
^
/usr/include/c++/4.0.0/ext/hashtable.h:1006:31: note: in instantiation of
member function '__gnu_cxx::hashtable<std::basic_string<char>,
std::basic_string<char>, __gnu_cxx::hash<std::basic_string<char> >,
std::_Identity<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
> >::_M_bkt_num' requested here
size_type __new_bucket = _M_bkt_num(__first->_M_val,
^
/usr/include/c++/4.0.0/ext/hashtable.h:438:2: note: in instantiation of member
function '__gnu_cxx::hashtable<std::basic_string<char>,
std::basic_string<char>, __gnu_cxx::hash<std::basic_string<char> >,
std::_Identity<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
> >::resize' requested here
resize(_M_num_elements + 1);
^
In file included from test.cc:1:
/usr/include/c++/4.0.0/ext/hash_set:206:43: note: in instantiation of member
function '__gnu_cxx::hashtable<std::basic_string<char>,
std::basic_string<char>, __gnu_cxx::hash<std::basic_string<char> >,
std::_Identity<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
> >::insert_unique' requested here
pair<typename _Ht::iterator, bool> __p = _M_ht.insert_unique(__obj);
^
test.cc:6:5: note: in instantiation of member function
'__gnu_cxx::hash_set<std::basic_string<char>,
__gnu_cxx::hash<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
>
>::insert' requested here
hs.insert("Hello world");
^
1 error generated.
Thoughts on what we'd like from this:
* Ideally, we should say "Please provide a specialization for
'__gnu_cxx::hash<std::string>' that provides a 'size_t operator()(const
std::string&) const' member function". I'm not sure how to get this though.
* Simply removing the definition of "template<class _Key>struct hash" in
hash_fun.h produces a better message:
In file included from test.cc:1:
In file included from /usr/include/c++/4.0.0/ext/hash_set:64:
/usr/include/c++/4.0.0/ext/hashtable.h:304:29: error: implicit instantiation of
undefined template '__gnu_cxx::hash<std::basic_string<char> >'
hasher _M_hash;
^
In file included from test.cc:1:
/usr/include/c++/4.0.0/ext/hash_set:102:11: note: in instantiation of template
class '__gnu_cxx::hashtable<std::basic_string<char>, std::basic_string<char>,
__gnu_cxx::hash<std::basic_string<char> >,
std::_Identity<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
> >' requested here
_Ht _M_ht;
^
test.cc:5:38: note: in instantiation of template class
'__gnu_cxx::hash_set<std::basic_string<char>,
__gnu_cxx::hash<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
>
>' requested here
__gnu_cxx::hash_set<std::string> hs;
^
In file included from test.cc:1:
In file included from /usr/include/c++/4.0.0/ext/hash_set:64:
In file included from /usr/include/c++/4.0.0/ext/hashtable.h:71:
/usr/include/c++/4.0.0/ext/hash_fun.h:71:12: note: template is declared here
struct hash ;
^
1 error generated.
... but this requires changing libstdc++ and waiting for it to roll out.
* In the "in instantiation of template class", we should avoid re-printing the
"__gnu_cxx::hashtable<std::basic_string<char>, std::basic_string<char>,
__gnu_cxx::hash<std::basic_string<char> >,
std::_Identity<std::basic_string<char> >,
std::equal_to<std::basic_string<char> >, std::allocator<std::basic_string<char>
> >" part. Perhaps we should replace it with "..." when it's the same as the
previous class name. Maybe say "in instantiation of member function from same
class '...::_M_bkt_num'.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list