From f7e7e9bd3cfd274b5a6741a56d226739b60d3685 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Fri, 7 Sep 2018 00:08:02 -0500 Subject: [PATCH] Fix issue 8736: Iterators to containers from different expressions (a.begin().x == b.begin().x) (#1370) --- lib/checkstl.cpp | 4 ++-- test/teststl.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 8c8408ce3..59eee855f 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -467,9 +467,9 @@ static const Token * getIteratorExpression(const Token * tok) if (iter2) return iter2; } 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(); - if (Token::Match(tok, "%name% ( !!)")) + if (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 8971a1cb9..ac704e4b6 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -705,6 +705,12 @@ private: " if(f().begin()+1 == f().end()+1) {}\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" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void iteratorSameExpression() {