SymbolDatabase: Refactor handling of variable declarations in if condition
This commit is contained in:
parent
5b9bc4918e
commit
0c1e979af7
|
@ -3543,14 +3543,7 @@ void Scope::getVariableList(const Settings* settings)
|
||||||
{
|
{
|
||||||
const Token *start;
|
const Token *start;
|
||||||
|
|
||||||
bool beforeBody = false;
|
if (bodyStart)
|
||||||
|
|
||||||
if (type == eIf) {
|
|
||||||
beforeBody = true;
|
|
||||||
start = classDef;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (bodyStart)
|
|
||||||
start = bodyStart->next();
|
start = bodyStart->next();
|
||||||
|
|
||||||
// global scope
|
// global scope
|
||||||
|
@ -3561,6 +3554,11 @@ void Scope::getVariableList(const Settings* settings)
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Variable declared in condition: if (auto x = bar())
|
||||||
|
if (Token::Match(classDef, "if|while ( %type%") && Token::simpleMatch(classDef->next()->astOperand2(), "=")) {
|
||||||
|
checkVariable(classDef->tokAt(2), defaultAccess(), settings);
|
||||||
|
}
|
||||||
|
|
||||||
AccessControl varaccess = defaultAccess();
|
AccessControl varaccess = defaultAccess();
|
||||||
for (const Token *tok = start; tok && tok != bodyEnd; tok = tok->next()) {
|
for (const Token *tok = start; tok && tok != bodyEnd; tok = tok->next()) {
|
||||||
// syntax error?
|
// syntax error?
|
||||||
|
@ -3569,9 +3567,7 @@ void Scope::getVariableList(const Settings* settings)
|
||||||
|
|
||||||
// Is it a function?
|
// Is it a function?
|
||||||
else if (tok->str() == "{") {
|
else if (tok->str() == "{") {
|
||||||
if (beforeBody && tok == bodyStart)
|
|
||||||
beforeBody = false;
|
|
||||||
else
|
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -3652,9 +3648,7 @@ void Scope::getVariableList(const Settings* settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for start of statement..
|
// Search for start of statement..
|
||||||
else if (beforeBody && !Token::simpleMatch(tok->previous(), "("))
|
else if (tok->previous() && !Token::Match(tok->previous(), ";|{|}|public:|protected:|private:"))
|
||||||
continue;
|
|
||||||
else if (!beforeBody && tok->previous() && !Token::Match(tok->previous(), ";|{|}|public:|protected:|private:"))
|
|
||||||
continue;
|
continue;
|
||||||
else if (tok->str() == ";")
|
else if (tok->str() == ";")
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue