From 81ccfde33000dcd1f2d47cf6c3525162c6caedda Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 19 Mar 2024 11:07:40 +0100 Subject: [PATCH] Fix #12525 false negative: constStatement --- lib/checkother.cpp | 2 ++ test/testincompletestatement.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index cce598aaf7c..627b25ee318 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"