diff --git a/lib/vf_settokenvalue.cpp b/lib/vf_settokenvalue.cpp index a1547339496..9c107952d7a 100644 --- a/lib/vf_settokenvalue.cpp +++ b/lib/vf_settokenvalue.cpp @@ -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)) { @@ -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); + } } } diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 220e6382c8a..fbcf56fff74 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -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() {