Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix for #11469 FP mismatchingContainerExpression warning #5674

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ bool CheckStl::checkIteratorPair(const Token* tok1, const Token* tok2)
}

if (Token::Match(tok1->astParent(), "%comp%|-")) {
if (astIsIntegral(tok1, false) || astIsIntegral(tok2, false) || astIsFloat(tok1, false) ||
astIsFloat(tok2, false))
if (astIsIntegral(tok1, true) || astIsIntegral(tok2, true) ||
astIsFloat(tok1, true) || astIsFloat(tok2, true))
return false;
}
const Token* iter1 = getIteratorExpression(tok1);
Expand Down
17 changes: 17 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,23 @@ class TestStl : public TestFixture {
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("bool f(const std::vector<int>& a, const std::vector<int>& b) {\n" // #11469
" return (a.begin() - a.end()) == (b.begin() - b.end());\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("struct S {\n"
" const std::vector<int>* vec() const { return &v; }\n"
" const std::vector<int> v;\n"
"};\n"
"void f(const S& a, const S& b) {\n"
" if (a.vec()->begin() - a.vec()->end() != b.vec()->begin() - b.vec()->end()) {}\n"
"}\n");
TODO_ASSERT_EQUALS("",
"[test.cpp:6]: (warning) Iterators to containers from different expressions 'a.vec()' and 'a.vec()' are used together.\n"
"[test.cpp:6]: (warning) Iterators to containers from different expressions 'b.vec()' and 'b.vec()' are used together.\n",
errout.str());
}

void iteratorSameExpression() {
Expand Down
Loading