Fix FP issue 8986: constArgument check warns for elements of const array (#1683)

This commit is contained in:
Paul Fultz II 2019-02-21 23:39:59 -06:00 committed by Daniel Marjamäki
parent 507c7a4388
commit 941dd79f0d
2 changed files with 16 additions and 1 deletions

View File

@ -1062,7 +1062,7 @@ bool isConstVarExpression(const Token *tok)
} }
if (Token::Match(tok, "( %type%")) if (Token::Match(tok, "( %type%"))
return isConstVarExpression(tok->astOperand1()); return isConstVarExpression(tok->astOperand1());
if (Token::Match(tok, "%cop%")) { if (Token::Match(tok, "%cop%|[|.")) {
if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1())) if (tok->astOperand1() && !isConstVarExpression(tok->astOperand1()))
return false; return false;
if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2())) if (tok->astOperand2() && !isConstVarExpression(tok->astOperand2()))

View File

@ -7574,6 +7574,21 @@ private:
" g(static_cast<int>(i));\n" " g(static_cast<int>(i));\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); 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());
} }
}; };