From 2184ad4b4bb5f7b71d9893aee125c33b5e53a31d Mon Sep 17 00:00:00 2001 From: firewave Date: Sun, 21 Aug 2022 17:53:18 +0200 Subject: [PATCH 1/4] cppcheck.cpp: reduced scope of a variable --- lib/cppcheck.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 949693cfe7f..ae03eb68e34 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -911,11 +911,12 @@ 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, tokenizer.list.getSourceFilePath(), From f7a01aa5c05c3a12a8535f2b7aee0695c7ef051e Mon Sep 17 00:00:00 2001 From: firewave Date: Sun, 21 Aug 2022 17:54:23 +0200 Subject: [PATCH 2/4] cppcheck.cpp: removed unnecessary severity checks --- lib/cppcheck.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index ae03eb68e34..97bd282b0f1 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -925,8 +925,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string e.id, Certainty::normal); - if (errmsg.severity == Severity::error || mSettings.severity.isEnabled(errmsg.severity)) - reportErr(errmsg); + reportErr(errmsg); } } From fec8a0b06b9a1c3e14fd0ad066e945af488809b0 Mon Sep 17 00:00:00 2001 From: firewave Date: Sun, 21 Aug 2022 17:54:33 +0200 Subject: [PATCH 3/4] cppcheck.cpp: avoid unnecessary copy --- lib/cppcheck.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 97bd282b0f1..bfc7bb31038 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -918,7 +918,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string locationList.push_back(loc); } } - ErrorMessage errmsg(locationList, + ErrorMessage errmsg(std::move(locationList), tokenizer.list.getSourceFilePath(), Severity::error, e.errorMessage, From f64630df3574e99738c1c6a17efab7c052d6c370 Mon Sep 17 00:00:00 2001 From: firewave Date: Sun, 21 Aug 2022 18:00:10 +0200 Subject: [PATCH 4/4] templatesimplifier.cpp: perform early exit in loop in `expandTemplate()` --- lib/templatesimplifier.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 83f51b22ae1..226cc1cd28f 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