Fixed #3360: "type const* var;" is now recognized as variable declaration.

This commit is contained in:
PKEuS 2012-03-24 15:10:06 +01:00
parent b964551424
commit e6bcab7c35
3 changed files with 13 additions and 2 deletions

View File

@ -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;

View File

@ -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% ;|=")) {

View File

@ -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<std::set<int> > intsets;");