diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2b973a798d6..ec38c85d124 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3470,7 +3470,7 @@ bool CheckClass::checkThisUseAfterFreeRecursive(const Scope *classScope, const F tok = tok->tokAt(2); } else if (Token::Match(tok, "%var% . reset ( )") && selfPointer == tok->variable()) freeToken = tok; - else if (Token::Match(tok->previous(), "!!. %name% (") && tok->function() && tok->function()->nestedIn == classScope) { + else if (Token::Match(tok->previous(), "!!. %name% (") && tok->function() && tok->function()->nestedIn == classScope && tok->function()->type == Function::eFunction) { if (isDestroyed) { thisUseAfterFree(selfPointer->nameToken(), freeToken, tok); return true; diff --git a/test/testclass.cpp b/test/testclass.cpp index bb57f47452b..e6191d50f4a 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8947,6 +8947,22 @@ class TestClass : public TestFixture { " done();\n" "}"); ASSERT_EQUALS("", errout_str()); + + checkThisUseAfterFree("class C {\n" // #13311 + "public:\n" + " static void init();\n" + "private:\n" + " C();\n" + " static C* self;\n" + " bool use;\n" + "};\n" + "C::C() { use = true; }\n" + "void C::init() {\n" + " if (self)\n" + " delete self;\n" + " self = new C();\n" + "}"); + ASSERT_EQUALS("", errout_str()); }