From e6bcab7c3547341bbd37f6aa379aca3efc25c0ec Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 24 Mar 2012 15:10:06 +0100 Subject: [PATCH] Fixed #3360: "type const* var;" is now recognized as variable declaration. --- lib/checkclass.cpp | 2 +- lib/symboldatabase.cpp | 2 +- test/testsymboldatabase.cpp | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index ed45fb49d..bee881f32 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1144,7 +1144,7 @@ void CheckClass::thisSubtractionError(const Token *tok) void CheckClass::checkConst() { - // This is an inconclusive check. False positives: #2340, #3322, #3360. + // This is an inconclusive check. False positives: #2340, #3322. if (!_settings->inconclusive) return; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index ce6515c53..b6564de67 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1948,7 +1948,7 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const } } } else if (Token::Match(localTypeTok, "%type%")) { - localVarTok = skipPointers(localTypeTok->next()); + localVarTok = skipPointers(localTypeTok->strAt(1)=="const"?localTypeTok->tokAt(2):localTypeTok->next()); } if (Token::Match(localVarTok, "%var% ;|=")) { diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 5f33f3f2c..98fb21bf9 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -97,6 +97,7 @@ private: TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable); TEST_CASE(isVariableDeclarationIdentifiesReference); TEST_CASE(isVariableDeclarationDoesNotIdentifyTemplateClass); + TEST_CASE(isVariableDeclarationPointerConst); TEST_CASE(canFindMatchingBracketsNeedsOpen); TEST_CASE(canFindMatchingBracketsInnerPair); TEST_CASE(canFindMatchingBracketsOuterPair); @@ -434,6 +435,16 @@ private: ASSERT(false == isReference); } + void isVariableDeclarationPointerConst() { + reset(); + givenACodeSampleToTokenize var("std::string const* s;"); + bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok, isArray, isPointer, isReference); + ASSERT_EQUALS(true, result); + ASSERT(false == isArray); + ASSERT(true == isPointer); + ASSERT(false == isReference); + } + void canFindMatchingBracketsNeedsOpen() { reset(); givenACodeSampleToTokenize var("std::deque > intsets;");