diff --git a/lib/astutils.cpp b/lib/astutils.cpp index a2ef0c9c2..26f3ba195 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1062,7 +1062,7 @@ bool isConstVarExpression(const Token *tok) } if (Token::Match(tok, "( %type%")) return isConstVarExpression(tok->astOperand1()); - if (Token::Match(tok, "%cop%")) { + if (Token::Match(tok, "%cop%|[|.")) { if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1())) return false; if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2())) diff --git a/test/testother.cpp b/test/testother.cpp index ec6f50da2..ba56b2a93 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -7574,6 +7574,21 @@ private: " g(static_cast(i));\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #8986 + check("void f(int);\n" + "void g() {\n" + " const int x[] = { 10, 10 };\n" + " f(x[0]);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + check("void f(int);\n" + "void g() {\n" + " int x[] = { 10, 10 };\n" + " f(x[0]);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } };