diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f855dbffc..11cb732b7 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -908,6 +908,9 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listprevious(), "%op%|;|{|}|) ::| %name%") || (Token::Match(tok->previous(), "( ::| %name%") && (!rettail || rettail->str() != "loop"))) { + if (tok->str() == "::") + tok = tok->next(); + if (Token::Match(tok, "%varid% ?", varid)) tok = tok->tokAt(2); diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 2128cfb5b..44a9c784a 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1048,7 +1048,7 @@ static Token * createAstAtToken(Token *tok, bool cpp) return tok->linkAt(1); if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) { - if (cpp && Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%")) + if (cpp && (Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%") || Token::Match(tok->tokAt(-3), "[;{}] :: new|delete %name%"))) tok = tok->previous(); Token * const tok1 = tok; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index ebdb93290..aac5f5c4d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -365,6 +365,7 @@ private: TEST_CASE(gnucfg); TEST_CASE(trac3991); TEST_CASE(crash); + TEST_CASE(trac7680); } std::string getcode(const char code[], const char varname[], bool classfunc=false) { @@ -3931,6 +3932,14 @@ private: "}"); ASSERT_EQUALS("", errout.str()); } + + void trac7680() { + check("void foo() {\n" + " int *i = ::new int;\n" + " ::delete i;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestMemleakInFunction)