Skip to content

Commit 3170c17

Browse files
Amend fix for #12564 (#6231)
1 parent 2b88ca8 commit 3170c17

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ static bool isExecutableScope(const Token* tok)
123123
return false;
124124
}
125125

126+
static bool isEnumDefinition(const Token* tok)
127+
{
128+
if (!Token::Match(tok, "enum class| %name% {|:"))
129+
return false;
130+
while (!Token::Match(tok, "[{:]"))
131+
tok = tok->next();
132+
if (tok->str() == "{")
133+
return true;
134+
tok = tok->next(); // skip ':'
135+
while (Token::Match(tok, "%name%|::"))
136+
tok = tok->next();
137+
return Token::simpleMatch(tok, "{");
138+
}
139+
126140
void SymbolDatabase::createSymbolDatabaseFindAllScopes()
127141
{
128142
// create global scope
@@ -163,8 +177,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
163177
if ((tok->isCpp() && tok->isKeyword() &&
164178
((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") &&
165179
!Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|using|)|(|<")) ||
166-
(Token::Match(tok, "enum class| %name% {") ||
167-
Token::Match(tok, "enum class| %name% : %name% ::|{"))))
180+
isEnumDefinition(tok)))
168181
|| (tok->isC() && tok->isKeyword() && Token::Match(tok, "struct|union|enum %name% {"))) {
169182
const Token *tok2 = tok->tokAt(2);
170183

test/testsymboldatabase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6372,6 +6372,7 @@ class TestSymbolDatabase : public TestFixture {
63726372
void enum17() {
63736373
{
63746374
GET_SYMBOL_DB("struct S {\n" // #12564
6375+
" enum class E : std::uint8_t;\n"
63756376
" enum class E : std::uint8_t { E0 };\n"
63766377
" static void f(S::E e) {\n"
63776378
" if (e == S::E::E0) {}\n"

0 commit comments

Comments
 (0)