SymbolDatabase: Add variable in if condition 'if (auto x = bar())'
This commit is contained in:
parent
7e8ee31678
commit
3776604f06
|
@ -3543,7 +3543,10 @@ void Scope::getVariableList(const Settings* settings)
|
||||||
{
|
{
|
||||||
const Token *start;
|
const Token *start;
|
||||||
|
|
||||||
if (bodyStart)
|
if (type == eIf)
|
||||||
|
start = classDef;
|
||||||
|
|
||||||
|
else if (bodyStart)
|
||||||
start = bodyStart->next();
|
start = bodyStart->next();
|
||||||
|
|
||||||
// global scope
|
// global scope
|
||||||
|
@ -3642,7 +3645,7 @@ 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 (tok->previous() && !Token::Match(tok->previous(), ";|{|}|(|public:|protected:|private:"))
|
||||||
continue;
|
continue;
|
||||||
else if (tok->str() == ";")
|
else if (tok->str() == ";")
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -141,6 +141,7 @@ private:
|
||||||
TEST_CASE(isVariableDeclarationPointerConst);
|
TEST_CASE(isVariableDeclarationPointerConst);
|
||||||
TEST_CASE(isVariableDeclarationRValueRef);
|
TEST_CASE(isVariableDeclarationRValueRef);
|
||||||
TEST_CASE(isVariableDeclarationDoesNotIdentifyCase);
|
TEST_CASE(isVariableDeclarationDoesNotIdentifyCase);
|
||||||
|
TEST_CASE(isVariableDeclarationIf);
|
||||||
TEST_CASE(isVariableStlType);
|
TEST_CASE(isVariableStlType);
|
||||||
TEST_CASE(isVariablePointerToConstPointer);
|
TEST_CASE(isVariablePointerToConstPointer);
|
||||||
TEST_CASE(isVariablePointerToVolatilePointer);
|
TEST_CASE(isVariablePointerToVolatilePointer);
|
||||||
|
@ -831,6 +832,18 @@ private:
|
||||||
ASSERT_EQUALS("a", b->typeStartToken()->str());
|
ASSERT_EQUALS("a", b->typeStartToken()->str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void isVariableDeclarationIf() {
|
||||||
|
GET_SYMBOL_DB("void foo() {\n"
|
||||||
|
" for (auto& elem : items) {\n"
|
||||||
|
" if (auto x = bar()) {}\n"
|
||||||
|
" }\n"
|
||||||
|
"}");
|
||||||
|
const Token *x = Token::findsimplematch(tokenizer.tokens(), "x");
|
||||||
|
ASSERT(x);
|
||||||
|
ASSERT(x->varId());
|
||||||
|
ASSERT(x->variable());
|
||||||
|
}
|
||||||
|
|
||||||
void VariableValueType1() {
|
void VariableValueType1() {
|
||||||
GET_SYMBOL_DB("typedef uint8_t u8;\n"
|
GET_SYMBOL_DB("typedef uint8_t u8;\n"
|
||||||
"static u8 x;\n");
|
"static u8 x;\n");
|
||||||
|
|
Loading…
Reference in New Issue