I get errors when I try to compile the following bit of code:
#include
int main()
{
std::tr1::unordered_set s;
const std::tr1::unordered_set &s_ref = s;
s_ref.find(27); // Problem is here.
return 0;
}
It appears that hashtable::find_node should be marked as a const member
function and isn't. Putting const in (see below) seems to let the thing work,
though I haven't tested it rigorously.
debian-800:/usr/include/c++/4.0/tr1# diff hashtable-orig hashtable-fixed
863c863
< node* find_node (node* p, const key_type& k, typename
hashtable::hash_code_t c);
---
> node* find_node (node* p, const key_type& k, typename hashtable::hash_code_t
c) const;
1219c1219
< ::find_node (node* p, const key_type& k, typename hashtable::hash_code_t code)
---
> ::find_node (node* p, const key_type& k, typename hashtable::hash_code_t code)
const
Here's the full text of the error I get:
[EMAIL PROTECTED]:~/c$ g++-4.0 -v -save-temps -fmessage-length=80 temp.cpp
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls
--without-included-gettext --enable-threads=posix --program-suffix=-4.0
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.1 (Debian 4.0.1-2)
/usr/lib/gcc/i486-linux-gnu/4.0.1/cc1plus -E -quiet -v -D_GNU_SOURCE temp.cpp
-mtune=i486 -fmessage-length=80 -fpch-preprocess -o temp.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/i486-linux-gnu/4.0.1/../../../../include/c++/4.0.1
/usr/lib/gcc/i486-linux-gnu/4.0.1/../../../../include/c++/4.0.1/i486-linux-gnu
/usr/lib/gcc/i486-linux-gnu/4.0.1/../../../../include/c++/4.0.1/backward
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.0.1/include
/usr/include
End of search list.
/usr/lib/gcc/i486-linux-gnu/4.0.1/cc1plus -fpreprocessed temp.ii -quiet
-dumpbase temp.cpp -mtune=i486 -auxbase temp -version -fmessage-length=80 -o
temp.s
GNU C++ version 4.0.1 (Debian 4.0.1-2) (i486-linux-gnu)
compiled by GNU C version 4.0.1 (Debian 4.0.1-2).
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32148
/usr/lib/gcc/i486-linux-gnu/4.0.1/../../../../include/c++/4.0.1/tr1/hashtable:
In
member function 'typename std::tr1::hashtable::const_iterator std::tr1::hashtable::find(const Key&) const
[with Key = int, Value = int, Allocator = std::allocator, ExtractKey =
Internal::identity, Equal = std::equal_to, H1 =
std::tr1::hash, H2 = Internal::mod_range_hashing, H =
Internal::default_ranged_hash, RehashPolicy = Internal::prime_rehash_policy,
bool cache_hash_code = false, bool mutable_iterators = false, bool
unique_keys = true]':
temp.cpp:9: instantiated from here
/usr/lib/gcc/i486-linux-gnu/4.0.1/../../../../include/c++/4.0.1/tr1/hashtable:1135:
error: passing
'const std::tr1::hashtable,
Internal::identity, std::equal_to, std::tr1::hash,
Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy, false, false, true>' as 'this' argument of '
typename std::tr1::hashtable::node*
std::tr1::hashtable::find_node(Internal::hash_node*, const
Key&, typename std::tr1::hashtable::hash_code_t) [with Key = int, Value = int, Allocator =
std::allocator, ExtractKey = Internal::identity, Equal =
std::equal_to, H1 = std::tr1::hash, H2 =
Internal::mod_range_hashing, H = Internal::default_ranged_hash, RehashPolicy
= Internal::prime_rehash_policy, bool cache_hash_code = false, bool
mutable_iterators = false, bool unique_keys = true]' discards qualifiers
--
Summary: Const-correctness issue in TR1 hashtable
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: evilalias at hotmail dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i486-linux-gnu
GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23053