This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/52476] [C++11] Unordered multimap reorders equivalent elements
- From: "daniel.kruegler at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 04 Mar 2012 16:10:19 +0000
- Subject: [Bug libstdc++/52476] [C++11] Unordered multimap reorders equivalent elements
- Auto-submitted: auto-generated
- References: <bug-52476-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52476
--- Comment #2 from Daniel KrÃgler <daniel.kruegler at googlemail dot com> 2012-03-04 16:10:19 UTC ---
(In reply to comment #1)
> (we should double check that by avoiding any use of
> fancy C++11 features like initializer lists in the testcase)
I rewrote the testcase in C++03 form and based on TR1 unordered map:
//------
#include <tr1/unordered_map>
#include <iostream>
#include <utility>
typedef std::tr1::unordered_multimap<int, int> map_type;
void printHashTable(const map_type& map)
{
for (unsigned i = 0; i < map.bucket_count(); ++i) {
std::cout << "b[" << i << "]:" << std::endl;
for (map_type::const_local_iterator it = map.begin(i); it != map.end(i);
++it) {
std::cout << " " << map.hash_function()(it->first) << " ["
<< it->first << "," << it->second << "]" << std::endl;
}
}
std::cout << "----------------------" << std::endl;
}
int main()
{
typedef std::pair<int, int> P;
const P input1[] = {
P(0,0),
P(1,0),
P(2,0),
P(3,0),
P(4,0),
P(1,1)
};
map_type dict(input1, input1 + sizeof(input1)/sizeof(input1[0]));
printHashTable(dict);
const P input2[] = {
P(3,1),
P(3,2),
P(5,0)
};
dict.insert(input2, input2 + sizeof(input2)/sizeof(input2[0]));
printHashTable(dict);
dict.max_load_factor(0.5);
printHashTable(dict);
}
//------
The incorrect runtime behaviour is unchanged compared to the original form.
This means, one could actually remove the [C++11] tag from the bug title.