From 043b4999701606cc31fcbedf6e1f4daa15e76cb6 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 1 Sep 2023 17:13:46 -0500 Subject: [PATCH 1/2] Fix 11889: FP knownArgument with array element --- lib/checkother.cpp | 3 +-- test/testother.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e75688e9542..4253e9344eb 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3704,8 +3704,7 @@ static bool isVariableExpression(const Token* tok) return isVariableExpression(tok->astOperand1()) && isVariableExpression(tok->astOperand2()); if (Token::simpleMatch(tok, "[")) - return isVariableExpression(tok->astOperand1()) && - tok->astOperand2() && tok->astOperand2()->hasKnownIntValue(); + return isVariableExpression(tok->astOperand1()); return false; } diff --git a/test/testother.cpp b/test/testother.cpp index 4f5782e6d90..bb0dc15100a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11041,6 +11041,20 @@ class TestOther : public TestFixture { " if (g(k(i))) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #11889 + check("struct S {\n" + " int a[5];\n" + " void f(int i);\n" + "}\n" + "void g(int);\n" + "void S::f(int i) {\n" + " if (a[i] == 1) {\n" + " a[i] = 0;\n" + " g(a[i]);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void knownArgumentHiddenVariableExpression() { From 2178a72f87bc7f7969319ed9cd045410d45bd1b6 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 1 Sep 2023 17:16:06 -0500 Subject: [PATCH 2/2] Format --- test/testother.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index bb0dc15100a..64ed1731e26 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11044,16 +11044,16 @@ class TestOther : public TestFixture { // #11889 check("struct S {\n" - " int a[5];\n" - " void f(int i);\n" - "}\n" - "void g(int);\n" - "void S::f(int i) {\n" - " if (a[i] == 1) {\n" - " a[i] = 0;\n" - " g(a[i]);\n" - " }\n" - "}\n"); + " int a[5];\n" + " void f(int i);\n" + "}\n" + "void g(int);\n" + "void S::f(int i) {\n" + " if (a[i] == 1) {\n" + " a[i] = 0;\n" + " g(a[i]);\n" + " }\n" + "}\n"); ASSERT_EQUALS("", errout.str()); }