From 4ebdf5fae19c54f03d84a7a471867e47da838eb2 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Sat, 7 Jan 2023 22:10:07 +0100 Subject: [PATCH] Fix #11478 FP identicalConditionAfterEarlyExit when passing *this (#4684) --- lib/checkcondition.cpp | 2 +- test/testcondition.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index af3dab209..01484a479 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -790,7 +790,7 @@ void CheckCondition::multiCondition2() if (!function || !function->isConst()) break; } - if (Token::Match(tok->previous(), "[(,] %name% [,)]") && isParameterChanged(tok)) + if (Token::Match(tok->previous(), "[(,] *|& %name% [,)]") && isParameterChanged(tok)) break; } } diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 62e3731bc..d3deb0586 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -2887,6 +2887,23 @@ private: " return 0;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #11478 + check("struct S {\n" + " void run();\n" + " bool b = false;\n" + " const std::function f;\n" + "};\n" + "void S::run() {\n" + " while (true) {\n" + " if (b)\n" + " return;\n" + " f(*this);\n" + " if (b)\n" + " return;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void innerConditionModified() {