From 818ebb8d7e5f6fd193ff1660d99919d1628347ae Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 29 Jun 2023 07:42:53 +0200 Subject: [PATCH] Fix autovarInvalidDeallocation regression (#5203) --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 8dca09906..6e4322ebf 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -303,7 +303,7 @@ void CheckAutoVariables::autoVariables() if (v.isImpossible()) continue; if ((v.isTokValue() && (isArrayVar(v.tokvalue) || ((v.tokvalue->tokType() == Token::eString)))) || - (v.isLocalLifetimeValue() && v.lifetimeKind == ValueFlow::Value::LifetimeKind::Address)) { + (v.isLocalLifetimeValue() && v.lifetimeKind == ValueFlow::Value::LifetimeKind::Address && !Token::simpleMatch(v.tokvalue, "("))) { errorInvalidDeallocation(tok, &v); break; } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index c4f8aa108..5fbe371f6 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -847,6 +847,12 @@ private: " return 0;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f() {\n" + " S* p = &g();\n" + " delete p;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void testinvaliddealloc_input() {