| 3831 | } |
| 3832 | |
| 3833 | bool CheckClass::analyseWholeProgram(const CTU::FileInfo &ctu, const std::list<const Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) |
| 3834 | { |
| 3835 | (void)ctu; |
| 3836 | (void)settings; |
| 3837 | |
| 3838 | CheckClassImpl dummy(nullptr, settings, errorLogger); |
| 3839 | dummy. |
| 3840 | logChecker("CheckClass::analyseWholeProgram"); |
| 3841 | |
| 3842 | if (fileInfo.empty()) |
| 3843 | return false; |
| 3844 | |
| 3845 | bool foundErrors = false; |
| 3846 | |
| 3847 | std::unordered_map<std::string, MyFileInfo::NameLoc> all; |
| 3848 | |
| 3849 | for (const Check::FileInfo* fi1 : fileInfo) { |
| 3850 | const auto *fi = dynamic_cast<const MyFileInfo*>(fi1); |
| 3851 | if (!fi) |
| 3852 | continue; |
| 3853 | for (const MyFileInfo::NameLoc &nameLoc : fi->classDefinitions) { |
| 3854 | auto it = all.find(nameLoc.className); |
| 3855 | if (it == all.end()) { |
| 3856 | all[nameLoc.className] = nameLoc; |
| 3857 | continue; |
| 3858 | } |
| 3859 | if (it->second.hash == nameLoc.hash) |
| 3860 | continue; |
| 3861 | if (it->second.fileName == nameLoc.fileName && it->second.configuration != nameLoc.configuration) |
| 3862 | continue; |
| 3863 | // Same location, sometimes the hash is different wrongly (possibly because of different token simplifications). |
| 3864 | if (it->second.isSameLocation(nameLoc)) |
| 3865 | continue; |
| 3866 | |
| 3867 | std::list<ErrorMessage::FileLocation> locationList; |
| 3868 | locationList.emplace_back(nameLoc.fileName, nameLoc.lineNumber, nameLoc.column); |
| 3869 | locationList.emplace_back(it->second.fileName, it->second.lineNumber, it->second.column); |
| 3870 | |
| 3871 | const ErrorMessage errmsg(std::move(locationList), |
| 3872 | fi->file0, |
| 3873 | Severity::error, |
| 3874 | "$symbol:" + nameLoc.className + |
| 3875 | "\nThe one definition rule is violated, different classes/structs have the same name '$symbol'", |
| 3876 | "ctuOneDefinitionRuleViolation", |
| 3877 | CWE_ONE_DEFINITION_RULE, |
| 3878 | Certainty::normal); |
| 3879 | errorLogger.reportErr(errmsg); |
| 3880 | |
| 3881 | foundErrors = true; |
| 3882 | } |
| 3883 | } |
| 3884 | return foundErrors; |
| 3885 | } |
| 3886 | |
| 3887 | void CheckClass::runChecks(const Tokenizer &tokenizer, ErrorLogger& errorLogger) |
| 3888 | { |
nothing calls this directly
no test coverage detected