Fixed #5627 (False positive assignBoolToPointer)
This commit is contained in:
parent
088664d626
commit
225fb96554
|
@ -31,7 +31,7 @@ namespace {
|
|||
|
||||
static bool astIsBool(const Token *expr)
|
||||
{
|
||||
return Token::Match(expr, "%comp%|%bool%|%oror%|&&|!");
|
||||
return Token::Match(expr, "%comp%|%bool%|%oror%|&&|!") && !expr->link();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -2707,7 +2707,7 @@ void Tokenizer::createLinks2()
|
|||
else if (token->str() == ">" || token->str() == ">>") {
|
||||
if (type.empty() || type.top()->str() != "<") // < and > don't match.
|
||||
continue;
|
||||
if (token->next() && !Token::Match(token->next(), "%var%|>|>>|&|*|::|,|(|)|{|;"))
|
||||
if (token->next() && !Token::Match(token->next(), "%var%|>|>>|&|*|::|,|(|)|{|;|["))
|
||||
continue;
|
||||
|
||||
// Check type of open link
|
||||
|
@ -2715,11 +2715,14 @@ void Tokenizer::createLinks2()
|
|||
continue;
|
||||
|
||||
// if > is followed by ; .. "new a<b>;" is expected
|
||||
if (Token::simpleMatch(token->next(), ";")) {
|
||||
// if > is followed by [ .. "new a<b>[" is expected
|
||||
if (Token::Match(token->next(), ";|[")) {
|
||||
Token *prev = type.top()->previous();
|
||||
while (prev && Token::Match(prev->previous(), ":: %var%"))
|
||||
prev = prev->tokAt(-2);
|
||||
if (!prev || !prev->previous() || prev->previous()->str() != "new")
|
||||
if (prev && prev->str() != "new")
|
||||
prev = prev->previous();
|
||||
if (!prev || prev->str() != "new")
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -131,6 +131,12 @@ private:
|
|||
" s.p = true;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:6]: (error) Boolean value assigned to pointer.\n", errout.str());
|
||||
|
||||
// ticket #5627 - false positive: template
|
||||
check("void f() {\n"
|
||||
" X *p = new ::std::pair<int,int>[rSize];\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void comparisonOfBoolExpressionWithInt1() {
|
||||
|
|
|
@ -6840,6 +6840,24 @@ private:
|
|||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
{
|
||||
// #5627
|
||||
const char code[] = "new Foo<Bar>[10];";
|
||||
errout.str("");
|
||||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
const Token *tok = tokenizer.tokens();
|
||||
|
||||
ASSERT_EQUALS(true, tok->tokAt(2) == tok->linkAt(4));
|
||||
ASSERT_EQUALS(true, tok->tokAt(4) == tok->linkAt(2));
|
||||
ASSERT_EQUALS(true, tok->tokAt(5) == tok->linkAt(7));
|
||||
ASSERT_EQUALS(true, tok->tokAt(7) == tok->linkAt(5));
|
||||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
void removeExceptionSpecification1() {
|
||||
|
|
Loading…
Reference in New Issue