Skip to content

Commit a6d2c17

Browse files
Fix #15077 FP uninitvar for array of std::vector (#8908)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent c09ccdb commit a6d2c17

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

‎lib/checkclass.cpp‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,18 +1675,9 @@ void CheckClassImpl::checkMemsetType(const Scope *start, const Token *tok, const
16751675
}
16761676
// don't warn if variable static or const, pointer or array of pointers
16771677
if (!var.isStatic() && !var.isConst() && !var.isPointer() && (!var.isArray() || var.typeEndToken()->str() != "*")) {
1678-
const Token *tok1 = var.typeStartToken();
16791678
const Scope *typeScope = var.typeScope();
16801679

1681-
std::string typeName;
1682-
if (Token::Match(tok1, "%type% ::")) {
1683-
const Token *typeTok = tok1;
1684-
while (Token::Match(typeTok, "%type% ::")) {
1685-
typeName += typeTok->str() + "::";
1686-
typeTok = typeTok->tokAt(2);
1687-
}
1688-
typeName += typeTok->str();
1689-
}
1680+
const std::string typeName = var.getTypeName();
16901681

16911682
// check for std:: type
16921683
if (var.isStlType() && typeName != "std::array" && !mSettings.library.podtype(typeName)) {

‎lib/valueflow.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5944,7 +5944,7 @@ static bool needsInitialization(const Variable* var)
59445944
return true;
59455945
if (var->valueType()->type == ValueType::Type::ITERATOR)
59465946
return true;
5947-
if (var->isStlType() && var->isArray()) {
5947+
if (var->isStlType() && var->getTypeName() == "std::array") {
59485948
if (const Token* ctt = var->valueType()->containerTypeToken) {
59495949
if (ctt->isStandardType())
59505950
return true;

‎test/testuninitvar.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6840,6 +6840,12 @@ class TestUninitVar : public TestFixture {
68406840
" return a[0];\n"
68416841
"}\n");
68426842
ASSERT_EQUALS("", errout_str());
6843+
6844+
valueFlowUninit("std::vector<int> f() {\n" // #15077
6845+
" const std::vector<int> a[1];\n"
6846+
" return a[0];\n"
6847+
"}\n");
6848+
ASSERT_EQUALS("", errout_str());
68436849
}
68446850

68456851
void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value

0 commit comments

Comments
 (0)