diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 366aa20ff..a174e5a15 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1233,39 +1233,32 @@ const Token* skipPointers(const Token* tok) bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const Token*& typetok) const { const Token* localTypeTok = skipScopeIdentifiers(tok); + const Token* localVarTok = NULL; 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% ;")) + localVarTok = skipPointers(closeTok->next()); + + if (Token::Match(localVarTok, ":: %type% %var% ;")) { - vartok = closetok->next(); - typetok = localTypeTok; - } - else if (Token::Match(closetok, "> * %var% ;")) - { - vartok = closetok->tokAt(2); - typetok = localTypeTok; - } - else if (Token::Match(closetok, "> :: %type% %var% ;")) - { - vartok = closetok->tokAt(3); - typetok = closetok->tokAt(2); + localTypeTok = localVarTok->next(); + localVarTok = localVarTok->tokAt(2); } } } else if (Token::Match(localTypeTok, "%type%")) { - const Token* localVarTok = skipPointers(localTypeTok->next()); + localVarTok = skipPointers(localTypeTok->next()); + } - if (isSimpleVariable(localVarTok) || isArrayVariable(localVarTok)) - { - vartok = localVarTok; - typetok = localTypeTok; - } + if (isSimpleVariable(localVarTok) || isArrayVariable(localVarTok)) + { + vartok = localVarTok; + typetok = localTypeTok; } return NULL != vartok; diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d9e0956d3..a5632d7ff 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -62,6 +62,8 @@ private: TEST_CASE(test_isVariableDeclarationIdentifiesArray); TEST_CASE(test_isVariableDeclarationIdentifiesOfArrayPointers); TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerVariable); + TEST_CASE(isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable); + TEST_CASE(isVariableDeclarationIdentifiesTemplatedArrayVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariable); TEST_CASE(isVariableDeclarationIdentifiesTemplatedVariableIterator); TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable); @@ -222,6 +224,26 @@ private: ASSERT_EQUALS("set", typetok->str()); } + void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() + { + reset(); + givenACodeSampleToTokenize var("std::deque*** ints;"); + bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); + 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() { reset();