diff --git a/lib/astutils.cpp b/lib/astutils.cpp index a21ba54c3..d819fdd89 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -338,7 +338,7 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2 (Token::Match(tok2, "%name% <") && tok2->next()->link())) { // 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->str() != "dynamic_cast") return false; @@ -362,7 +362,10 @@ bool isSameExpression(bool cpp, bool macro, const Token *tok1, const Token *tok2 // bailout when we see ({..}) if (tok1->str() == "{") 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 *t2 = tok2->next(); while (t1 && t2 && diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index a538f80be..e49db3fba 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -471,7 +471,7 @@ static const Token * getIteratorExpression(const Token * tok) } else if (Token::Match(tok, "begin|cbegin|rbegin|crbegin|end|cend|rend|crend (")) { if (Token::Match(tok->previous(), ". %name% ( ) !!.")) 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 nullptr; diff --git a/test/teststl.cpp b/test/teststl.cpp index c94a9acaf..25d2b4e99 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -711,6 +711,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + check("template\n" + "std::vector& f();\n" + "void foo() {\n" + " if(f<1>().begin() == f<1>().end()) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + check("void f() {\n" " if (a.begin().x == b.begin().x) {}\n" " if (begin(a).x == begin(b).x) {}\n" @@ -723,6 +730,11 @@ private: " if (*a.begin() == *b.begin()) {}\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void foo() {\n" + " if(f().begin(1) == f().end()) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void iteratorSameExpression() {