Fixed #3360: "type const* var;" is now recognized as variable declaration.
This commit is contained in:
parent
b964551424
commit
e6bcab7c35
|
@ -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;
|
||||
|
||||
|
|
|
@ -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% ;|=")) {
|
||||
|
|
|
@ -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;");
|
||||
|
|
Loading…
Reference in New Issue