Skip to content

Commit 2d75160

Browse files
Fix #14973 FP assertWithSideEffect with function pointer comparison (#8792)
1 parent b391765 commit 2d75160

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/checkassert.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ void CheckAssertImpl::assertWithSideEffects()
7878
continue;
7979
}
8080

81+
const Token* parent = tmp->astParent();
82+
while (Token::Match(parent, ".|::"))
83+
parent = parent->astParent();
84+
if (!Token::simpleMatch(parent, "("))
85+
continue;
8186
const Function* f = tmp->function();
8287
const Scope* scope = f->functionScope;
8388
if (!scope) {

test/testassert.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ class TestAssert : public TestFixture {
147147
" assert(g());\n"
148148
"}\n");
149149
ASSERT_EQUALS("", errout_str());
150+
151+
check("int i;\n" // #14973
152+
"bool f() {\n"
153+
" i = 0;\n"
154+
" return true;\n"
155+
"}\n"
156+
"void g() {\n"
157+
" bool (*fp)() = f;\n"
158+
" assert(fp == f);\n"
159+
"}\n");
160+
ASSERT_EQUALS("", errout_str());
150161
}
151162

152163
void memberFunctionCallInAssert() {

0 commit comments

Comments
 (0)