diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 949693cfe..bfc7bb310 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -911,21 +911,21 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string ErrorMessage::FileLocation loc(e.token, &tokenizer.list); locationList.push_back(loc); } else { - ErrorMessage::FileLocation loc(tokenizer.list.getSourceFilePath(), 0, 0); ErrorMessage::FileLocation loc2(filename, 0, 0); locationList.push_back(loc2); - if (filename != tokenizer.list.getSourceFilePath()) + if (filename != tokenizer.list.getSourceFilePath()) { + ErrorMessage::FileLocation loc(tokenizer.list.getSourceFilePath(), 0, 0); locationList.push_back(loc); + } } - ErrorMessage errmsg(locationList, + ErrorMessage errmsg(std::move(locationList), tokenizer.list.getSourceFilePath(), Severity::error, e.errorMessage, e.id, Certainty::normal); - if (errmsg.severity == Severity::error || mSettings.severity.isEnabled(errmsg.severity)) - reportErr(errmsg); + reportErr(errmsg); } } diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 83f51b22a..226cc1cd2 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2179,6 +2179,10 @@ void TemplateSimplifier::expandTemplate( continue; } + // don't add instantiations in template definitions + if (!templates.empty()) + continue; + std::string scope; const Token *prev = tok3; for (; Token::Match(prev->tokAt(-2), "%name% ::"); prev = prev->tokAt(-2)) { @@ -2202,13 +2206,10 @@ void TemplateSimplifier::expandTemplate( } } - // don't add instantiations in template definitions - if (templates.empty()) { - if (copy) - newInstantiations.emplace_back(mTokenList.back(), scope); - else if (!inTemplateDefinition) - newInstantiations.emplace_back(tok3, scope); - } + if (copy) + newInstantiations.emplace_back(mTokenList.back(), scope); + else if (!inTemplateDefinition) + newInstantiations.emplace_back(tok3, scope); } // link() newly tokens manually