paleozogt
paleozogt

Reputation: 6573

std::map broken in alchemy?

The following code tests the use of std::map with std::string as a key:

#include <stdio.h>
#include <map>
#include <string>
using namespace std;

typedef map<string, int> test_map_t;

int main(int argc, char **argv) {
    test_map_t test_map;

    test_map["test1"]= 1;    
    test_map["test2"]= 2;
    test_map["test3"]= 3;    

    string tmp= "test1";
    printf("%s : %d \n", tmp.c_str(), test_map[tmp]);

    return 0;
}

When compiled with ordinary gcc, this test will print out "test1 : 1", as expected. However, when compiled with alchemy it will print "test1 : 3" (!). Something is very wrong here.

Are there any workarounds for this or am I just stuck?

Upvotes: 3

Views: 509

Answers (3)

babyshambles
babyshambles

Reputation: 36

class string is broken in alchemy. There is a bug in operator copy (=). map works fine with other class

Upvotes: 2

yadab
yadab

Reputation: 2143

Should not you use cstdio? But your code works perfectly with gcc version 4.4.2 20091027, i have tested it. Is it the complete code or something is there which might be overwriting the stack.

#include <cstdio>
#include <map>

Upvotes: 0

Steve Townsend
Steve Townsend

Reputation: 54178

Sure looks like a bug.

Typically the source code (headers) is part of STL distribution - can you step thru to find out what is going on? Compare source to GCC version maybe.

Seems like you have a cast-iron case to take this to the vendor for fix if confirmed.

Upvotes: 1

Related Questions