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()
|
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)
|
if (!_settings->inconclusive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -1948,7 +1948,7 @@ bool Scope::isVariableDeclaration(const Token* tok, const Token*& vartok, const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (Token::Match(localTypeTok, "%type%")) {
|
} 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% ;|=")) {
|
if (Token::Match(localVarTok, "%var% ;|=")) {
|
||||||
|
|
|
@ -97,6 +97,7 @@ private:
|
||||||
TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable);
|
TEST_CASE(isVariableDeclarationIdentifiesNestedTemplateVariable);
|
||||||
TEST_CASE(isVariableDeclarationIdentifiesReference);
|
TEST_CASE(isVariableDeclarationIdentifiesReference);
|
||||||
TEST_CASE(isVariableDeclarationDoesNotIdentifyTemplateClass);
|
TEST_CASE(isVariableDeclarationDoesNotIdentifyTemplateClass);
|
||||||
|
TEST_CASE(isVariableDeclarationPointerConst);
|
||||||
TEST_CASE(canFindMatchingBracketsNeedsOpen);
|
TEST_CASE(canFindMatchingBracketsNeedsOpen);
|
||||||
TEST_CASE(canFindMatchingBracketsInnerPair);
|
TEST_CASE(canFindMatchingBracketsInnerPair);
|
||||||
TEST_CASE(canFindMatchingBracketsOuterPair);
|
TEST_CASE(canFindMatchingBracketsOuterPair);
|
||||||
|
@ -434,6 +435,16 @@ private:
|
||||||
ASSERT(false == isReference);
|
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() {
|
void canFindMatchingBracketsNeedsOpen() {
|
||||||
reset();
|
reset();
|
||||||
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
givenACodeSampleToTokenize var("std::deque<std::set<int> > intsets;");
|
||||||
|
|
Loading…
Reference in New Issue