Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/vf_settokenvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ namespace ValueFlow
else if (Token::Match(parent, ":: %name%") && parent->astOperand2() == tok) {
setTokenValue(parent, std::move(value), settings);
}

// Calling std::size or std::empty on an array
else if (value.isTokValue() && Token::simpleMatch(value.tokvalue, "{") && tok->variable() &&
tok->variable()->isArray() && Token::Match(parent->previous(), "%name% (") && astIsRHS(tok)) {
Expand All @@ -724,5 +725,10 @@ namespace ValueFlow
}
}
}

// C++ constructor
else if (value.isIntValue() && parent->str() == "{" && parent->valueType() && (parent->valueType()->isIntegral() || parent->valueType()->pointer > 0)) {
setTokenValue(parent, std::move(value), settings);
}
}
}
2 changes: 2 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,8 @@ class TestValueFlow : public TestFixture {
"void foo() { x = N::e1; }";
ASSERT_EQUALS(1, valueOfTok(code, "::").intvalue);
}

ASSERT_EQUALS(63, valueOfTok("x = 3 * uint32_t{21};", "*").intvalue);
}

void valueFlowString() {
Expand Down
Loading