SymbolDatabase: Added testcase for variable in if-scope
This commit is contained in:
parent
3776604f06
commit
9f4db5018d
|
@ -3543,8 +3543,12 @@ void Scope::getVariableList(const Settings* settings)
|
||||||
{
|
{
|
||||||
const Token *start;
|
const Token *start;
|
||||||
|
|
||||||
if (type == eIf)
|
bool beforeBody = false;
|
||||||
|
|
||||||
|
if (type == eIf) {
|
||||||
|
beforeBody = true;
|
||||||
start = classDef;
|
start = classDef;
|
||||||
|
}
|
||||||
|
|
||||||
else if (bodyStart)
|
else if (bodyStart)
|
||||||
start = bodyStart->next();
|
start = bodyStart->next();
|
||||||
|
@ -3565,6 +3569,9 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -3645,7 +3652,9 @@ void Scope::getVariableList(const Settings* settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for start of statement..
|
// Search for start of statement..
|
||||||
else if (tok->previous() && !Token::Match(tok->previous(), ";|{|}|(|public:|protected:|private:"))
|
else if (beforeBody && !Token::simpleMatch(tok->previous(), "("))
|
||||||
|
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;
|
||||||
|
|
|
@ -835,13 +835,18 @@ private:
|
||||||
void isVariableDeclarationIf() {
|
void isVariableDeclarationIf() {
|
||||||
GET_SYMBOL_DB("void foo() {\n"
|
GET_SYMBOL_DB("void foo() {\n"
|
||||||
" for (auto& elem : items) {\n"
|
" for (auto& elem : items) {\n"
|
||||||
" if (auto x = bar()) {}\n"
|
" if (auto x = bar()) { int y = 3; }\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}");
|
"}");
|
||||||
const Token *x = Token::findsimplematch(tokenizer.tokens(), "x");
|
const Token *x = Token::findsimplematch(tokenizer.tokens(), "x");
|
||||||
ASSERT(x);
|
ASSERT(x);
|
||||||
ASSERT(x->varId());
|
ASSERT(x->varId());
|
||||||
ASSERT(x->variable());
|
ASSERT(x->variable());
|
||||||
|
|
||||||
|
const Token *y = Token::findsimplematch(tokenizer.tokens(), "y");
|
||||||
|
ASSERT(y);
|
||||||
|
ASSERT(y->varId());
|
||||||
|
ASSERT(y->variable());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VariableValueType1() {
|
void VariableValueType1() {
|
||||||
|
|
Loading…
Reference in New Issue