http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51538
Bug #: 51538 Summary: std::set::insert(InputIterator first, InputIterator last) makes set uniterable Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: greenscape...@gmail.com Here source exaple: ////////////////////////////////////////////////// #include <set> #include <cstdlib> #include <cstdio> #include <cstdlib> typedef char FOO[8]; void randomFOO(FOO * uidl) { for(int i = 0; i < sizeof(uidl); ++i) { unsigned char byte = rand() * 256 / RAND_MAX; *((char*)uidl + i) = byte; } } struct FOOwrapper { FOOwrapper(const FOO * uidl) { memcpy(&m_uidl, uidl, sizeof(FOO)); } FOOwrapper(const FOOwrapper & othr) { memcpy(&m_uidl, &othr.m_uidl, sizeof(FOO)); } const FOOwrapper & operator=(const FOOwrapper & othr) { memcpy(&m_uidl, &othr.m_uidl, sizeof(FOO)); return *this; } bool operator<(const FOOwrapper & othr) const { return memcmp(&m_uidl, &othr.m_uidl, sizeof(FOO)); } FOO m_uidl; }; std::set<FOOwrapper> fooset; static const int size = 5; //#define SIMPLE_INSERT int main(int argc, char *argv[]) { FOOwrapper * wrap = static_cast<FOOwrapper *>(malloc(size*sizeof(FOOwrapper))); for(int i = 0; i < size; ++i) { FOO uidl; randomFOO(&uidl); new (wrap + i) FOOwrapper(&uidl); #ifdef SIMPLE_INSERT fooset.insert(wrap[i]); #endif } #ifndef SIMPLE_INSERT fooset.insert(wrap, wrap + size); #endif printf("size: %d\n\n", fooset.size()); std::set<FOOwrapper>::const_iterator it = fooset.begin(); for(int i = 0; it != fooset.end(); ++it,++i) printf("%d\n", i); free(wrap); return 0; } ////////////////////////////////////////////////// if SIMPLE_INSERT is not defined then output will be: size: <value of variable size> 0 1 No matter how many elements being inserted output always is the same. In other words we are limited to iterating only trough 2 elements. if SIMPLE_INSERT is defined, ie used std::set::insert(const value_type& x) method, then iterating through collection is proper. This source code, compiled with VSC++ 2010 works fine in both cases.