Skip to content

Commit 61bd8fd

Browse files
Partial fix for #11469 FP mismatchingContainerExpression warning (#5674)
1 parent 3e47acd commit 61bd8fd

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

lib/checkstl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ bool CheckStl::checkIteratorPair(const Token* tok1, const Token* tok2)
747747
}
748748

749749
if (Token::Match(tok1->astParent(), "%comp%|-")) {
750-
if (astIsIntegral(tok1, false) || astIsIntegral(tok2, false) || astIsFloat(tok1, false) ||
751-
astIsFloat(tok2, false))
750+
if (astIsIntegral(tok1, true) || astIsIntegral(tok2, true) ||
751+
astIsFloat(tok1, true) || astIsFloat(tok2, true))
752752
return false;
753753
}
754754
const Token* iter1 = getIteratorExpression(tok1);

test/teststl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,23 @@ class TestStl : public TestFixture {
19891989
" }\n"
19901990
"}\n");
19911991
ASSERT_EQUALS("", errout.str());
1992+
1993+
check("bool f(const std::vector<int>& a, const std::vector<int>& b) {\n" // #11469
1994+
" return (a.begin() - a.end()) == (b.begin() - b.end());\n"
1995+
"}\n");
1996+
ASSERT_EQUALS("", errout.str());
1997+
1998+
check("struct S {\n"
1999+
" const std::vector<int>* vec() const { return &v; }\n"
2000+
" const std::vector<int> v;\n"
2001+
"};\n"
2002+
"void f(const S& a, const S& b) {\n"
2003+
" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\n"
2004+
"}\n");
2005+
TODO_ASSERT_EQUALS("",
2006+
"[test.cpp:6]: (warning) Iterators to containers from different expressions 'a.vec()' and 'a.vec()' are used together.\n"
2007+
"[test.cpp:6]: (warning) Iterators to containers from different expressions 'b.vec()' and 'b.vec()' are used together.\n",
2008+
errout.str());
19922009
}
19932010

19942011
void iteratorSameExpression() {

0 commit comments

Comments
 (0)