问题
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?
回答1:
class string is broken in alchemy. There is a bug in operator copy (=). map works fine with other class
回答2:
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.
回答3:
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>
来源:https://stackoverflow.com/questions/3756250/stdmap-broken-in-alchemy