@@ -153,6 +153,8 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
153
153
return endInitList.top ().second == scope;
154
154
};
155
155
156
+ std::stack<const Token*> inIfCondition;
157
+
156
158
auto addLambda = [this , &scope](const Token* tok, const Token* lambdaEndToken) -> const Token* {
157
159
const Token* lambdaStartToken = lambdaEndToken->link ();
158
160
const Token* argStart = lambdaStartToken->astParent ();
@@ -732,7 +734,8 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
732
734
scope->checkVariable (tok->tokAt (2 ), AccessControl::Local, mSettings ); // check for variable declaration and add it to new scope if found
733
735
else if (scope->type == Scope::eCatch)
734
736
scope->checkVariable (tok->tokAt (2 ), AccessControl::Throw, mSettings ); // check for variable declaration and add it to new scope if found
735
- tok = scopeStartTok;
737
+ tok = tok->next ();
738
+ inIfCondition.push (scopeStartTok);
736
739
} else if (Token::Match (tok, " %var% {" )) {
737
740
endInitList.emplace (tok->linkAt (1 ), scope);
738
741
tok = tok->next ();
@@ -741,6 +744,8 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
741
744
} else if (tok->str () == " {" ) {
742
745
if (inInitList ()) {
743
746
endInitList.emplace (tok->link (), scope);
747
+ } else if (!inIfCondition.empty () && tok == inIfCondition.top ()) {
748
+ inIfCondition.pop ();
744
749
} else if (isExecutableScope (tok)) {
745
750
scopeList.emplace_back (this , tok, scope, Scope::eUnconditional, tok);
746
751
scope->nestedList .push_back (&scopeList.back ());
0 commit comments