Fix some FPs in mismatchingContainerExpression (#1402)
This commit is contained in:
parent
5c0fd0d5b4
commit
4ed22f1ff8
|
@ -338,7 +338,7 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
||||||
(Token::Match(tok2, "%name% <") && tok2->next()->link())) {
|
(Token::Match(tok2, "%name% <") && tok2->next()->link())) {
|
||||||
|
|
||||||
// non-const template function that is not a dynamic_cast => return false
|
// non-const template function that is not a dynamic_cast => return false
|
||||||
if (Token::simpleMatch(tok1->next()->link(), "> (") &&
|
if (pure && Token::simpleMatch(tok1->next()->link(), "> (") &&
|
||||||
!(tok1->function() && tok1->function()->isConst()) &&
|
!(tok1->function() && tok1->function()->isConst()) &&
|
||||||
tok1->str() != "dynamic_cast")
|
tok1->str() != "dynamic_cast")
|
||||||
return false;
|
return false;
|
||||||
|
@ -362,7 +362,10 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2
|
||||||
// bailout when we see ({..})
|
// bailout when we see ({..})
|
||||||
if (tok1->str() == "{")
|
if (tok1->str() == "{")
|
||||||
return false;
|
return false;
|
||||||
if (tok1->str() == "(" && tok1->previous() && !tok1->previous()->isName()) { // cast => assert that the casts are equal
|
// cast => assert that the casts are equal
|
||||||
|
if (tok1->str() == "(" && tok1->previous() &&
|
||||||
|
!tok1->previous()->isName() &&
|
||||||
|
!(tok1->previous()->str() == ">" && tok1->previous()->link())) {
|
||||||
const Token *t1 = tok1->next();
|
const Token *t1 = tok1->next();
|
||||||
const Token *t2 = tok2->next();
|
const Token *t2 = tok2->next();
|
||||||
while (t1 && t2 &&
|
while (t1 && t2 &&
|
||||||
|
|
|
@ -471,7 +471,7 @@ static const Token * getIteratorExpression(const Token * tok)
|
||||||
} else if (Token::Match(tok, "begin|cbegin|rbegin|crbegin|end|cend|rend|crend (")) {
|
} else if (Token::Match(tok, "begin|cbegin|rbegin|crbegin|end|cend|rend|crend (")) {
|
||||||
if (Token::Match(tok->previous(), ". %name% ( ) !!."))
|
if (Token::Match(tok->previous(), ". %name% ( ) !!."))
|
||||||
return tok->previous()->astOperand1();
|
return tok->previous()->astOperand1();
|
||||||
if (Token::Match(tok, "%name% ( !!)") && !Token::simpleMatch(tok->linkAt(1), ") ."))
|
if (!Token::simpleMatch(tok->previous(), ".") && Token::Match(tok, "%name% ( !!)") && !Token::simpleMatch(tok->linkAt(1), ") ."))
|
||||||
return tok->next()->astOperand2();
|
return tok->next()->astOperand2();
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -711,6 +711,13 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("template<int N>\n"
|
||||||
|
"std::vector<int>& f();\n"
|
||||||
|
"void foo() {\n"
|
||||||
|
" if(f<1>().begin() == f<1>().end()) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" if (a.begin().x == b.begin().x) {}\n"
|
" if (a.begin().x == b.begin().x) {}\n"
|
||||||
" if (begin(a).x == begin(b).x) {}\n"
|
" if (begin(a).x == begin(b).x) {}\n"
|
||||||
|
@ -723,6 +730,11 @@ private:
|
||||||
" if (*a.begin() == *b.begin()) {}\n"
|
" if (*a.begin() == *b.begin()) {}\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo() {\n"
|
||||||
|
" if(f().begin(1) == f().end()) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void iteratorSameExpression() {
|
void iteratorSameExpression() {
|
||||||
|
|
Loading…
Reference in New Issue