ValueFlow: Fix sizeof for array of library type

This commit is contained in:
Daniel Marjamäki 2019-03-13 18:31:41 +01:00
parent d5c5feafb2
commit b984897526
2 changed files with 8 additions and 0 deletions

View File

@ -943,6 +943,8 @@ static Token * valueFlowSetConstantValue(const Token *tok, const Settings *setti
size = settings->sizeof_int;
if (var->type()->classScope && var->type()->classScope->enumType)
size = getSizeOfType(var->type()->classScope->enumType, settings);
} else if (var->valueType()) {
size = getSizeOf(*var->valueType(), settings);
} else if (!var->type()) {
size = getSizeOfType(var->typeStartToken(), settings);
}

View File

@ -924,6 +924,12 @@ private:
CHECK(": wchar_t", settings.sizeof_wchar_t);
CHECK(": size_t", settings.sizeof_size_t);
#undef CHECK
code = "uint16_t arr[10];\n"
"x = sizeof(arr);";
values = tokenValues(code,"( arr )");
ASSERT_EQUALS(1U, values.size());
ASSERT_EQUALS(10 * sizeof(uint16_t), values.back().intvalue);
}
void valueFlowErrorPath() {