From e2081e85496744fe0b7900807b1d55853e7f92ac Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:51:26 +0100 Subject: [PATCH] Fix #12525 false negative: constStatement (#6155) --- lib/checkother.cpp | 2 ++ test/testincompletestatement.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 53595c4ad0e..331cb03be27 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1784,6 +1784,8 @@ static bool isType(const Token * tok, bool unknown) { if (tok && (tok->isStandardType() || (!tok->isKeyword() && Token::Match(tok, "%type%")) || tok->str() == "auto")) return true; + if (tok && tok->varId()) + return false; if (Token::simpleMatch(tok, "::")) return isType(tok->astOperand2(), unknown); if (Token::simpleMatch(tok, "<") && tok->link()) diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index 4be5ef1838c..a19cf6088df 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -666,6 +666,11 @@ class TestIncompleteStatement : public TestFixture { "}\n", /*inconclusive*/ true); ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n", errout_str()); + check("void f(int x, int y) {\n" // #12525 + " x * y;\n" + "}\n", /*inconclusive*/ true); + ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Found suspicious operator '*', result is not used.\n", errout_str()); + check("void f() {\n" // #5475 " std::string(\"a\") + \"a\";\n" "}\n"