Skip to content

Commit

Permalink
Fix #13442 FP uninitMemberVar with deleted default constructor (#7120)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 21, 2024
1 parent bb5a114 commit 85eadd8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3392,6 +3392,8 @@ void SymbolDatabase::addClassFunction(Scope *&scope, const Token *&tok, const To
auto range = scope1->functionMap.equal_range(tok->str());
for (std::multimap<std::string, const Function*>::const_iterator it = range.first; it != range.second; ++it) {
auto * func = const_cast<Function *>(it->second);
if (destructor && func->type != Function::Type::eDestructor)
continue;
if (!func->hasBody()) {
if (func->argsMatch(scope1, func->argDef, tok->next(), path, path_length)) {
const Token *closeParen = tok->linkAt(1);
Expand Down
37 changes: 37 additions & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class TestSymbolDatabase : public TestFixture {
TEST_CASE(symboldatabase105);
TEST_CASE(symboldatabase106);
TEST_CASE(symboldatabase107);
TEST_CASE(symboldatabase108);

TEST_CASE(createSymbolDatabaseFindAllScopes1);
TEST_CASE(createSymbolDatabaseFindAllScopes2);
Expand Down Expand Up @@ -5673,6 +5674,42 @@ class TestSymbolDatabase : public TestFixture {
}
}

void symboldatabase108() {
{
GET_SYMBOL_DB("struct S {\n" // #13442
" S() = delete;\n"
" S(int a) : i(a) {}\n"
" ~S();\n"
" int i;\n"
"};\n"
"S::~S() = default;\n");
ASSERT_EQUALS(db->scopeList.size(), 3);
auto scope = db->scopeList.begin();
++scope;
ASSERT_EQUALS(scope->className, "S");
const auto& flist = scope->functionList;
ASSERT_EQUALS(flist.size(), 3);
auto it = flist.begin();
ASSERT_EQUALS(it->name(), "S");
ASSERT_EQUALS(it->tokenDef->linenr(), 2);
ASSERT(it->isDelete());
ASSERT(!it->isDefault());
ASSERT_EQUALS(it->type, Function::Type::eConstructor);
++it;
ASSERT_EQUALS(it->name(), "S");
ASSERT_EQUALS(it->tokenDef->linenr(), 3);
ASSERT(!it->isDelete());
ASSERT(!it->isDefault());
ASSERT_EQUALS(it->type, Function::Type::eConstructor);
++it;
ASSERT_EQUALS(it->name(), "S");
ASSERT_EQUALS(it->tokenDef->linenr(), 4);
ASSERT(!it->isDelete());
ASSERT(it->isDefault());
ASSERT_EQUALS(it->type, Function::Type::eDestructor);
}
}

void createSymbolDatabaseFindAllScopes1() {
GET_SYMBOL_DB("void f() { union {int x; char *p;} a={0}; }");
ASSERT(db->scopeList.size() == 3);
Expand Down

0 comments on commit 85eadd8

Please sign in to comment.