Skip to content

Commit 8483063

Browse files
committed
Improved fix danmar#6636: (False positive unreadVariable - scope analysis seems to fail to False positive unreadVariable)
1 parent 4ceb246 commit 8483063

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/tokenize.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,17 @@ static const Token * isFunctionHead(const Token *tok, const std::string &endsWit
8080
return nullptr;
8181
}
8282

83-
static bool isClassStructUnionStart(const Token * tok)
83+
/**
84+
* is tok the start brace { of a class, struct, union, or enum
85+
*/
86+
static bool isClassStructUnionEnumStart(const Token * tok)
8487
{
85-
if (tok->str() != "{")
88+
if (!Token::Match(tok->previous(), "class|struct|union|enum|%name%|>|>> {"))
8689
return false;
8790
const Token * tok2 = tok->previous();
88-
while (tok2 && !Token::Match(tok2, "class|struct|union|{|;"))
91+
while (tok2 && !Token::Match(tok2, "class|struct|union|enum|{|}|;"))
8992
tok2 = tok2->previous();
90-
return Token::Match(tok2, "class|struct|union");
93+
return Token::Match(tok2, "class|struct|union|enum");
9194
}
9295

9396
//---------------------------------------------------------------------------
@@ -2612,7 +2615,7 @@ void Tokenizer::setVarId()
26122615
isExecutable = true;
26132616
} else {
26142617
isExecutable = ((scopeStack.top().isExecutable || initlist || tok->strAt(-1) == "else") &&
2615-
!isClassStructUnionStart(tok));
2618+
!isClassStructUnionEnumStart(tok));
26162619
scopeInfo.push(variableId);
26172620
}
26182621
initlist = false;

0 commit comments

Comments
 (0)