From 53c28022a36e432e29978441cb71cb7de8a70833 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 1 Aug 2022 00:18:19 +0200 Subject: [PATCH 1/4] #11233 FP: knownConditionTrueFalse (wrong message text) --- lib/astutils.cpp | 4 ++-- test/testcondition.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index b3bc58dda36..e1d5bd80ab9 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -948,7 +948,7 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth) return false; } else if (onVar && expr->variable()) { const Variable* var = expr->variable(); - return (var->isPrivate() || var->isPublic() || var->isProtected()); + return ((var->isPrivate() || var->isPublic() || var->isProtected()) && !var->isStatic()); } if (Token::simpleMatch(expr, ".")) return exprDependsOnThis(expr->astOperand1(), onVar, depth); @@ -2581,7 +2581,7 @@ bool isThisChanged(const Token* tok, int indirect, const Settings* settings, boo if ((Token::Match(tok->previous(), "%name% (") && !Token::simpleMatch(tok->astOperand1(), ".")) || Token::Match(tok->tokAt(-3), "this . %name% (")) { if (tok->previous()->function()) { - return (!tok->previous()->function()->isConst()); + return (!tok->previous()->function()->isConst() && !tok->previous()->function()->isStatic()); } else if (!tok->previous()->isKeyword()) { return true; } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index fc8a9f16de3..a033ad39ec7 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4239,6 +4239,17 @@ class TestCondition : public TestFixture { " return col;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct S {\n" + " static std::string m;\n" + " static void f() { m = \"abc\"; }\n" + " static void g() {\n" + " m.clear();\n" + " f();\n" + " if (m.empty()) {}\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueSymbolic() From 788982b0cb813413fec75ff2086e281c27d6c136 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Mon, 1 Aug 2022 00:27:28 +0200 Subject: [PATCH 2/4] Format --- lib/astutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e1d5bd80ab9..410eeaf917d 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2581,7 +2581,7 @@ bool isThisChanged(const Token* tok, int indirect, const Settings* settings, boo if ((Token::Match(tok->previous(), "%name% (") && !Token::simpleMatch(tok->astOperand1(), ".")) || Token::Match(tok->tokAt(-3), "this . %name% (")) { if (tok->previous()->function()) { - return (!tok->previous()->function()->isConst() && !tok->previous()->function()->isStatic()); + return (!tok->previous()->function()->isConst() && !tok->previous()->function()->isStatic()); } else if (!tok->previous()->isKeyword()) { return true; } From c59ae44ea75a3cb3c73be5a92313e17af07e7d45 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 1 Aug 2022 11:01:07 +0200 Subject: [PATCH 3/4] Update testcondition.cpp --- test/testcondition.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index a033ad39ec7..2e8a884f7af 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4240,7 +4240,7 @@ class TestCondition : public TestFixture { "}\n"); ASSERT_EQUALS("", errout.str()); - check("struct S {\n" + check("struct S {\n" // #11233 " static std::string m;\n" " static void f() { m = \"abc\"; }\n" " static void g() {\n" From 85a754af3951f82383367518ddb7d02713dea98c Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 2 Aug 2022 16:19:45 +0200 Subject: [PATCH 4/4] Trigger CI