Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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