keys in a std::set get changed on insert

Viewed 89

I currently have a very weird issue where the following code misbehaves:

std::set<int> simpleSet;
for( int i=0; i<10; ++i )
    simpleSet.insert( i );

Yes, it's really just inserting (or emplacing, same result) something into a set. Anyway, up to i=6 everything is fine but upon inserting 7 the set goes from

Locals
    i   7   int
    simpleSet   <7 items>   std::set<int, std::less<int>, std::allocator<int> >
        [0] 0   int
        [1] 1   int
        [2] 2   int
        [3] 3   int
        [4] 4   int
        [5] 5   int
        [6] 6   int

to

Locals
    i   8   int
    simpleSet   <8 items>   std::set<int, std::less<int>, std::allocator<int> >
        [0] 0   int
        [1] 1   int
        [2] 2   int
        [3] 1   int
        [4] 2   int
        [5] 1   int
        [6] 2   int
        [7] 1   int

in the debugger. This is reproducable with other datatypes and random values. Always on inserting the 8th element all previous elements are changed. Inserting more just adds more 1s and 2s to the set for some reason, and in new buckets.

I'm working on Linux with glibc version 2.26 and gcc 7.2.0 or clang 4.0.1 (both produce the same problem).

Edit: This is issue with the debug data visualizer in QtCreator (and maybe other IDEs). When writing the contents of the set to stdout it prints the correct values.

0 Answers
Related