Skip to content

Commit

Permalink
Fix 11848: Assert failure in getParentValueTypes() (danmar#5274)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Aug 2, 2023
1 parent 931a59a commit 389e446
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
28 changes: 20 additions & 8 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3490,16 +3490,28 @@ const Token *Type::initBaseInfo(const Token *tok, const Token *tok1)
return tok2;
}

const std::string& Type::name() const
std::string Type::name() const
{
const Token* next = classDef->next();
const Token* start = classDef->next();
if (classScope && classScope->enumClass && isEnumType())
return next->strAt(1);
if (next->str() == "class")
return next->strAt(1);
if (next->isName())
return next->str();
return emptyString;
start = start->tokAt(1);
else if (start->str() == "class")
start = start->tokAt(1);
else if (!start->isName())
return emptyString;
const Token* next = start;
while (Token::Match(next, "::|<|>|(|)|[|]|*|&|&&|%name%")) {
if (Token::Match(next, "<|(|[") && next->link())
next = next->link();
next = next->next();
}
std::string result;
for (const Token* tok = start; tok != next; tok = tok->next()) {
if (!result.empty())
result += ' ';
result += tok->str();
}
return result;
}

void SymbolDatabase::debugMessage(const Token *tok, const std::string &type, const std::string &msg) const
Expand Down
2 changes: 1 addition & 1 deletion lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class CPPCHECKLIB Type {
}
}

const std::string& name() const;
std::string name() const;

const std::string& type() const {
return classDef ? classDef->str() : emptyString;
Expand Down
8 changes: 8 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6812,6 +6812,14 @@ class TestValueFlow : public TestFixture {
" dummy_resource::log.clear();\n"
"}\n";
valueOfTok(code, "log");

code = "struct D : B<int> {\n"
" D(int i, const std::string& s) : B<int>(i, s) {}\n"
"};\n"
"template<> struct B<int>::S {\n"
" int j;\n"
"};\n";
valueOfTok(code, "B");
}

void valueFlowCrash() {
Expand Down

0 comments on commit 389e446

Please sign in to comment.