From a8cf63239a3d48ed3c1c7017d1c9f4e04680ce64 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 11 Nov 2015 16:59:13 +0100 Subject: [PATCH] Fixed false positive autovarInvalidDeallocation if deallocting result of member function (#6551) --- lib/checkautovariables.cpp | 7 +++++++ test/testautovariables.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 5e1d7e03b..e652b439e 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -76,6 +76,13 @@ bool CheckAutoVariables::isAutoVar(const Token *tok) return false; } + if (Token::Match(tok, "%name% .|::")) { + do { + tok = tok->tokAt(2); + } while (Token::Match(tok, "%name% .|::")); + if (Token::Match(tok, "%name% (")) + return false; + } return true; } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 70d20aabe..58fc254ba 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -592,6 +592,13 @@ private: " }\n" "};"); ASSERT_EQUALS("", errout.str()); + + // #6551 + check("bool foo( ) {\n" + " SwTxtFld * pTxtFld = GetFldTxtAttrAt();\n" + " delete static_cast(&pTxtFld->GetAttr());\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void testinvaliddealloc_C() {