'Klocwork' profiller generate the error ['it.second.name_._M_dataplus._M_p' might be used uninitialized in this function.] in following code section.
class Test {
public:
Test() { }
Test(std::string str) {
name = str;
cout <<"Test::Test object: " <<name <<endl;
}
~Test() {
cout <<"Test::~Test object: " <<name <<endl;
}
string getName() {
return name;
}
private:
string name;
};
class MapHandler {
private:
map<int, Test> myMap;
public:
void MapFiller();
void MapDisplay();
};
void MapHandler::MapFiller() {
Test obj1("Obj1");
Test obj2("Obj2");
Test obj3("Obj3");
myMap[1] = obj1;
myMap[2] = obj1;
myMap[3] = obj3;
}
void MapHandler::MapDisplay() {
map<int, Test> tmpMap;
for(auto it : myMap) {
cout <<"object: " << it.second.getName() <<endl;
tmpMap[it.first] = it.second;
} **//Error Line**
}
But in simple compilation using [g++ -std=c++11 -Wall -Werror test.cpp] it's working fine.
Aucun commentaire:
Enregistrer un commentaire