From 88df55c5da78baa67dbd15350d22fc1af19461d7 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 13 Mar 2024 21:59:36 +0100 Subject: [PATCH] Fix #12445 FP iterators3, mismatchingContainerIterator with reference after cast (#6124) --- lib/astutils.cpp | 2 +- test/teststl.cpp | 6 ++++++ test/testunusedvar.cpp | 4 +--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index e5c31c01f72..1a672ef000b 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1529,7 +1529,7 @@ static bool astIsBoolLike(const Token* tok) bool isSameExpression(bool macro, const Token *tok1, const Token *tok2, const Library& library, bool pure, bool followVar, ErrorPath* errors) { - if (tok1 == nullptr && tok2 == nullptr) + if (tok1 == tok2) return true; if (tok1 == nullptr || tok2 == nullptr) return false; diff --git a/test/teststl.cpp b/test/teststl.cpp index eeb3058e221..48f4f09b451 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -2208,6 +2208,12 @@ class TestStl : public TestFixture { " if (it != N::v.end()) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(void* p) {\n" // #12445 + " std::vector&v = *(std::vector*)(p);\n" + " v.erase(v.begin(), v.end());\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void eraseIteratorOutOfBounds() { diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 3358082d081..7a4996f9bc2 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -2910,9 +2910,7 @@ class TestUnusedVar : public TestFixture { " for (int i = 0; i < 10; )\n" " a[i++] = 0;\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", - "", - errout_str()); + ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a[i++]' is assigned a value that is never used.\n", errout_str()); } void localvar10() {