Fix 11848: Assert failure in getParentValueTypes() (#5274)

This commit is contained in:
Paul Fultz II 2023-08-02 04:29:19 -04:00 committed by GitHub
parent 931a59a724
commit 389e446dc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 9 deletions

View File

@ -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

View File

@ -131,7 +131,7 @@ public:
}
}
const std::string& name() const;
std::string name() const;
const std::string& type() const {
return classDef ? classDef->str() : emptyString;

View File

@ -6812,6 +6812,14 @@ private:
" 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() {