diff --git a/lib/checkassert.cpp b/lib/checkassert.cpp index 4578f7395ba..00bb95e319a 100644 --- a/lib/checkassert.cpp +++ b/lib/checkassert.cpp @@ -78,6 +78,11 @@ void CheckAssertImpl::assertWithSideEffects() continue; } + const Token* parent = tmp->astParent(); + while (Token::Match(parent, ".|::")) + parent = parent->astParent(); + if (!Token::simpleMatch(parent, "(")) + continue; const Function* f = tmp->function(); const Scope* scope = f->functionScope; if (!scope) { diff --git a/test/testassert.cpp b/test/testassert.cpp index ea170c43f2d..a76b8207445 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -147,6 +147,17 @@ class TestAssert : public TestFixture { " assert(g());\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("int i;\n" // #14973 + "bool f() {\n" + " i = 0;\n" + " return true;\n" + "}\n" + "void g() {\n" + " bool (*fp)() = f;\n" + " assert(fp == f);\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void memberFunctionCallInAssert() {