parent
b3762cd76a
commit
6960332f8a
|
@ -1164,10 +1164,11 @@ static Token * valueFlowSetConstantValue(Token *tok, const Settings *settings, b
|
|||
value.setKnown();
|
||||
setTokenValue(tok, value, settings);
|
||||
setTokenValue(tok->next(), value, settings);
|
||||
} else if (Token::Match(tok, "sizeof ( %var% ) / sizeof (") && tok->next()->astParent() == tok->tokAt(4)) {
|
||||
} else if (Token::Match(tok, "sizeof ( %var% ) /") && tok->next()->astParent() == tok->tokAt(4) &&
|
||||
tok->tokAt(4)->astOperand2() && Token::simpleMatch(tok->tokAt(4)->astOperand2()->previous(), "sizeof (")) {
|
||||
// Get number of elements in array
|
||||
const Token *sz1 = tok->tokAt(2);
|
||||
const Token *sz2 = tok->tokAt(6); // left parenthesis
|
||||
const Token *sz2 = tok->tokAt(4)->astOperand2(); // left parenthesis of sizeof on rhs
|
||||
const nonneg int varid1 = sz1->varId();
|
||||
if (varid1 &&
|
||||
sz1->variable() &&
|
||||
|
|
|
@ -1194,6 +1194,15 @@ private:
|
|||
ASSERT_EQUALS(1U, values.size());
|
||||
ASSERT_EQUALS(10, values.back().intvalue);
|
||||
|
||||
code = "void f() {\n" // #11294
|
||||
" struct S { int i; };\n"
|
||||
" const S a[] = { 1, 2 };\n"
|
||||
" x = sizeof(a) / ( sizeof(a[0]) );\n"
|
||||
"}";
|
||||
values = tokenValues(code, "/");
|
||||
ASSERT_EQUALS(1U, values.size());
|
||||
ASSERT_EQUALS(2, values.back().intvalue);
|
||||
|
||||
#define CHECK(A, B, C, D) \
|
||||
do { \
|
||||
code = "enum " A " E " B " { E0, E1 };\n" \
|
||||
|
|
Loading…
Reference in New Issue