From f1d66dd4e72e47200ce55503bfc765e4151812e0 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 17 Nov 2023 16:01:56 +0100 Subject: [PATCH 1/2] Partial fix for #11469 FP mismatchingContainerExpression warning --- lib/checkstl.cpp | 4 ++-- test/teststl.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 3d448c85f7a..35ad7bc1ca4 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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); diff --git a/test/teststl.cpp b/test/teststl.cpp index b545a52fc70..d79c0b320e8 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1989,6 +1989,23 @@ class TestStl : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("bool f(const std::vector& a, const std::vector& 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* vec() const { return &v; }\n" + " const std::vector 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() { From 581414257ab512348b895bac1fc4a8bcd56badfe Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 17 Nov 2023 16:34:23 +0100 Subject: [PATCH 2/2] Fix --- test/teststl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/teststl.cpp b/test/teststl.cpp index d79c0b320e8..523a0c59b52 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2004,7 +2004,7 @@ class TestStl : public TestFixture { "}\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", + "[test.cpp:6]: (warning) Iterators to containers from different expressions 'b.vec()' and 'b.vec()' are used together.\n", errout.str()); }