Skip to content

Commit

Permalink
Amend fix for #12564 (danmar#6231)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 4, 2024
1 parent 2b88ca8 commit 3170c17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit 3170c17

Please sign in to comment.