From c6f7fceaf999af67df363b0b1e574493513944ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 1 Jun 2026 11:11:47 +0200 Subject: [PATCH 1/2] add test --- test/testassert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testassert.cpp b/test/testassert.cpp index 651897af057..84282ebcb06 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -156,7 +156,7 @@ class TestAssert : public TestFixture { "void foo(SquarePack s) {\n" " assert( s.Foo() );\n" "}"); - ASSERT_EQUALS("[test.cpp:5:14]: (warning) Assert statement calls a function which may have desired side effects: 'Foo'. [assertWithSideEffect]\n", errout_str()); + ASSERT_EQUALS("", errout_str()); check("struct SquarePack {\n" " int Foo() const;\n" From f65dd76c625490a21fec054b65171cca066f42dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 1 Jun 2026 11:09:18 +0200 Subject: [PATCH 2/2] fix --- lib/checkassert.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/checkassert.cpp b/lib/checkassert.cpp index 8240304d83f..ab9b91181bc 100644 --- a/lib/checkassert.cpp +++ b/lib/checkassert.cpp @@ -80,12 +80,8 @@ void CheckAssertImpl::assertWithSideEffects() const Function* f = tmp->function(); const Scope* scope = f->functionScope; - if (!scope) { - // guess that const method doesn't have side effects - if (f->nestedIn->isClassOrStruct() && !f->isConst() && !f->isStatic()) - sideEffectInAssertError(tmp, f->name()); // Non-const member function called, assume it has side effects + if (!scope) continue; - } for (const Token *tok2 = scope->bodyStart; tok2 != scope->bodyEnd; tok2 = tok2->next()) { if (!tok2->isAssignmentOp() && tok2->tokType() != Token::eIncDecOp)