diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 31bf15a2a..ac7a63a8e 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1236,24 +1236,21 @@ bool SymbolDatabase::SpaceInfo::isVariableDeclaration(const Token* tok, const To if (Token::Match(localTypeTok, "%type% < ")) { - const Token* closetok = NULL; - bool found = findClosingBracket(localTypeTok->next(), closetok); + const Token* closeTok = NULL; + bool found = findClosingBracket(localTypeTok->next(), closeTok); if (found) { - if (Token::Match(closetok, "> %var% ;")) + const Token* localVarTok = skipPointers(closeTok->next()); + + if (isSimpleVariable(localVarTok) || isArrayVariable(localVarTok)) { - vartok = closetok->next(); + vartok = localVarTok; typetok = localTypeTok; } - else if (Token::Match(closetok, "> * %var% ;")) + else if (Token::Match(closeTok, "> :: %type% %var% ;")) { - vartok = closetok->tokAt(2); - typetok = localTypeTok; - } - else if (Token::Match(closetok, "> :: %type% %var% ;")) - { - vartok = closetok->tokAt(3); - typetok = closetok->tokAt(2); + vartok = closeTok->tokAt(3); + typetok = closeTok->tokAt(2); } } } diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index b63cc4088..7f52f80d6 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -64,6 +64,7 @@ private: TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers); TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable); + TEST_CASE(isVariableDeclarationIdentifiesTemplatedArrayVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator); TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable); @@ -229,15 +230,19 @@ private: reset(); givenACodeSampleToTokenize var("std::deque*** ints;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); - TODO_ASSERT_EQUALS(true, result); - if (NULL != vartok) - { - TODO_ASSERT_EQUALS("ints", vartok->str()); - } - if (NULL != typetok) - { - TODO_ASSERT_EQUALS("deque", typetok->str()); - } + ASSERT_EQUALS(true, result); + ASSERT_EQUALS("ints", vartok->str()); + ASSERT_EQUALS("deque", typetok->str()); + } + + void isVariableDeclarationIdentifiesTemplatedArrayVariable() + { + reset(); + givenACodeSampleToTokenize var("std::deque ints[3];"); + bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); + ASSERT_EQUALS(true, result); + ASSERT_EQUALS("ints", vartok->str()); + ASSERT_EQUALS("deque", typetok->str()); } void isVariableDeclarationIdentifiesTemplatedVariable()