Skip to content

Commit 818ebb8

Browse files
Fix autovarInvalidDeallocation regression (#5203)
1 parent 1b4ec0d commit 818ebb8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/checkautovariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void CheckAutoVariables::autoVariables()
303303
if (v.isImpossible())
304304
continue;
305305
if ((v.isTokValue() && (isArrayVar(v.tokvalue) || ((v.tokvalue->tokType() == Token::eString)))) ||
306-
(v.isLocalLifetimeValue() && v.lifetimeKind == ValueFlow::Value::LifetimeKind::Address)) {
306+
(v.isLocalLifetimeValue() && v.lifetimeKind == ValueFlow::Value::LifetimeKind::Address && !Token::simpleMatch(v.tokvalue, "("))) {
307307
errorInvalidDeallocation(tok, &v);
308308
break;
309309
}

test/testautovariables.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,12 @@ class TestAutoVariables : public TestFixture {
847847
" return 0;\n"
848848
"}\n");
849849
ASSERT_EQUALS("", errout.str());
850+
851+
check("void f() {\n"
852+
" S* p = &g();\n"
853+
" delete p;\n"
854+
"}\n");
855+
ASSERT_EQUALS("", errout.str());
850856
}
851857

852858
void testinvaliddealloc_input() {

0 commit comments

Comments
 (0)