Fix FP constStatement with more complex expression (#3959)
This commit is contained in:
parent
32ded1602b
commit
c85e7e7d2f
|
@ -1778,7 +1778,7 @@ static bool isConstStatement(const Token *tok, bool cpp)
|
|||
if (Token::simpleMatch(tok->previous(), "sizeof ("))
|
||||
return true;
|
||||
if (isCPPCast(tok)) {
|
||||
if (Token::simpleMatch(tok->astOperand1(), "dynamic_cast") && Token::simpleMatch(tok->astOperand1()->next()->link()->previous(), "& >"))
|
||||
if (Token::simpleMatch(tok->astOperand1(), "dynamic_cast") && Token::simpleMatch(tok->astOperand1()->linkAt(1)->previous(), "& >"))
|
||||
return false;
|
||||
return isWithoutSideEffects(cpp, tok) && isConstStatement(tok->astOperand2(), cpp);
|
||||
}
|
||||
|
@ -1793,7 +1793,10 @@ static bool isConstStatement(const Token *tok, bool cpp)
|
|||
const Token* lml = previousBeforeAstLeftmostLeaf(tok);
|
||||
if (lml)
|
||||
lml = lml->next();
|
||||
return lml && !isLikelyStream(cpp, lml) && isConstStatement(tok->astOperand2(), cpp);
|
||||
const Token* stream = lml;
|
||||
while (stream && Token::Match(stream->astParent(), ".|[|("))
|
||||
stream = stream->astParent();
|
||||
return (!stream || !isLikelyStream(cpp, stream)) && isConstStatement(tok->astOperand2(), cpp);
|
||||
}
|
||||
}
|
||||
if (Token::simpleMatch(tok, "?") && Token::simpleMatch(tok->astOperand2(), ":")) // ternary operator
|
||||
|
|
|
@ -377,6 +377,25 @@ private:
|
|||
" V << a, b, c, d;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct S { Eigen::Vector4d V; };\n"
|
||||
"struct T { int a, int b, int c, int d; };\n"
|
||||
"void f(S& s, const T& t) {\n"
|
||||
" s.V << t.a, t.b, t.c, t.d;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("struct S { Eigen::Vector4d V[2]; };\n"
|
||||
"void f(int a, int b, int c, int d) {\n"
|
||||
" S s[1];\n"
|
||||
" s[0].V[1] << a, b, c, d;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" a.b[4][3].c()->d << x , y, z;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// #8451
|
||||
|
|
Loading…
Reference in New Issue