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
17 changes: 15 additions & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ static bool isExecutableScope(const Token* tok)
return false;
}

static bool isEnumDefinition(const Token* tok)
{
if (!Token::Match(tok, "enum class| %name% {|:"))
return false;
while (!Token::Match(tok, "[{:]"))
tok = tok->next();
if (tok->str() == "{")
return true;
tok = tok->next(); // skip ':'
while (Token::Match(tok, "%name%|::"))
tok = tok->next();
return Token::simpleMatch(tok, "{");
}

void SymbolDatabase::createSymbolDatabaseFindAllScopes()
{
// create global scope
Expand Down Expand Up @@ -163,8 +177,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
if ((tok->isCpp() && tok->isKeyword() &&
((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") &&
!Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|using|)|(|<")) ||
(Token::Match(tok, "enum class| %name% {") ||
Token::Match(tok, "enum class| %name% : %name% ::|{"))))
isEnumDefinition(tok)))
|| (tok->isC() && tok->isKeyword() && Token::Match(tok, "struct|union|enum %name% {"))) {
const Token *tok2 = tok->tokAt(2);

Expand Down
1 change: 1 addition & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6372,6 +6372,7 @@ class TestSymbolDatabase : public TestFixture {
void enum17() {
{
GET_SYMBOL_DB("struct S {\n" // #12564
" enum class E : std::uint8_t;\n"
" enum class E : std::uint8_t { E0 };\n"
" static void f(S::E e) {\n"
" if (e == S::E::E0) {}\n"
Expand Down