From ffbcfae98856487a5cf85bbc5c6eee2b837817f6 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 2 Sep 2023 07:29:38 -0500 Subject: [PATCH] Fix 11889: FP knownArgument with array element (#5395) --- 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 66954f066..13ae85df4 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 3d9f24be6..829265a37 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -11053,6 +11053,20 @@ private: " 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() {