From fc6a791a746900d7b35dd19f6ec0fd7a67cf5dba Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 3 Oct 2021 02:59:51 -0500 Subject: [PATCH] Fix 9766: False positive; suspicious operator is written in declaration (#3476) --- lib/tokenize.cpp | 3 ++- test/testother.cpp | 5 +++++ test/testunusedfunctions.cpp | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ed0b9a530..6cfcaf93c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4013,7 +4013,8 @@ void Tokenizer::setVarIdPass1() if (tok && tok->str() == "<") { const Token *end = tok->findClosingBracket(); while (tok != end) { - if (tok->isName()) { + if (tok->isName() && !(Token::simpleMatch(tok->next(), "<") && + Token::Match(tok->tokAt(-2), "std :: %name%"))) { const std::map::const_iterator it = variableMap.find(tok->str()); if (it != variableMap.end()) tok->varId(it->second); diff --git a/test/testother.cpp b/test/testother.cpp index 4b14e7cc0..df55ca7b4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4589,6 +4589,11 @@ private: " for (p = path; *p++;) ;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " std::array,3> array;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void duplicateBranch() { diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 7fb54c417..678b720f4 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -47,6 +47,7 @@ private: TEST_CASE(template4); // #9805 TEST_CASE(template5); TEST_CASE(template6); // #10475 crash + TEST_CASE(template7); // #9766 crash TEST_CASE(throwIsNotAFunction); TEST_CASE(unusedError); TEST_CASE(unusedMain); @@ -268,6 +269,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void template7() + { // #9766 + check("void f() {\n" + " std::array,3> array;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:1]: (style) The function 'f' is never used.\n", errout.str()); + } + void throwIsNotAFunction() { check("struct A {void f() const throw () {}}; int main() {A a; a.f();}"); ASSERT_EQUALS("", errout.str());