From 56b65402e5a6efced2c793a865149f4c998f1622 Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 3 May 2022 18:49:35 +0200 Subject: [PATCH 1/2] Fix #11034 FN duplicateCondition with struct member --- lib/astutils.cpp | 2 +- test/testcondition.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 6e18f3aad9b..e06f9f49574 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2399,7 +2399,7 @@ static bool isExpressionChangedAt(const F& getExprTok, if (depth < 0) return true; if (tok->exprId() != exprid) { - if (globalvar && Token::Match(tok, "%name% (")) + if (globalvar && !tok->isKeyword() && Token::Match(tok, "%name% (")) // TODO: Is global variable really changed by function call? return true; const bool pointer = astIsPointer(tok); diff --git a/test/testcondition.cpp b/test/testcondition.cpp index 4b94009b50d..dc8253e9229 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4802,6 +4802,17 @@ class TestCondition : public TestFixture { "}\n"); ASSERT_EQUALS("", errout.str()); + check("struct S { int i; };\n" + "int f(const S & s) {\n" + " int a = 0, b = 0;\n" + " if (s.i == 0)\n" + " a = 1;\n" + " if (s.i == 0)\n" + " b = 1;\n" + " return a + b;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) The if condition is the same as the previous if condition\n", errout.str()); + // do not crash check("void assign(const MMA& other) {\n" " if (mPA.cols != other.mPA.cols || mPA.rows != other.mPA.rows)\n" From f5ccc3df455766d7dff993f382260b9be450afc8 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 3 May 2022 18:54:34 +0200 Subject: [PATCH 2/2] 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 dc8253e9229..ec772412ec2 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4803,7 +4803,7 @@ class TestCondition : public TestFixture { ASSERT_EQUALS("", errout.str()); check("struct S { int i; };\n" - "int f(const S & s) {\n" + "int f(const S& s) {\n" " int a = 0, b = 0;\n" " if (s.i == 0)\n" " a = 1;\n"