One definition rule; avoid false positives when location is same

This commit is contained in:
Daniel Marjamäki 2021-02-10 11:44:05 +01:00
parent fbf63b932e
commit c2c40a18fd
2 changed files with 8 additions and 2 deletions

View File

@ -2952,6 +2952,9 @@ bool CheckClass::analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<C
} }
if (it->second.hash == nameLoc.hash) if (it->second.hash == nameLoc.hash)
continue; continue;
// Same location, sometimes the hash is different wrongly (possibly because of different token simplifications).
if (it->second.isSameLocation(nameLoc))
continue;
std::list<ErrorMessage::FileLocation> locationList; std::list<ErrorMessage::FileLocation> locationList;
locationList.emplace_back(nameLoc.fileName, nameLoc.lineNumber, nameLoc.column); locationList.emplace_back(nameLoc.fileName, nameLoc.lineNumber, nameLoc.column);

View File

@ -161,10 +161,13 @@ public:
std::size_t hash; std::size_t hash;
bool operator==(const NameLoc& other) const { bool operator==(const NameLoc& other) const {
return isSameLocation(other) && hash == other.hash;
}
bool isSameLocation(const NameLoc& other) const {
return fileName == other.fileName && return fileName == other.fileName &&
lineNumber == other.lineNumber && lineNumber == other.lineNumber &&
column == other.column && column == other.column;
hash == other.hash;
} }
}; };
std::vector<NameLoc> classDefinitions; std::vector<NameLoc> classDefinitions;