From ea4e6a60f707bfe2740e4f6ebe7599125555b368 Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Wed, 24 Oct 2018 13:32:37 -0400 Subject: [PATCH] Fix template simplifier from deleting the same declaration multiple times (#1449) Found by running valgrind on testrunner. May fix #8808. --- lib/templatesimplifier.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 04c27cdb3..008a8e38c 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -398,9 +398,9 @@ bool TemplateSimplifier::removeTemplate(Token *tok) else if (tok2->str() == "{") { tok2 = tok2->link()->next(); - eraseTokens(tok, tok2); if (tok2 && tok2->str() == ";" && tok2->next()) - deleteToken(tok->next()); + tok2 = tok2->next(); + eraseTokens(tok, tok2); deleteToken(tok); return true; } else if (tok2->str() == "}") { // garbage code! (#3449) @@ -2023,8 +2023,14 @@ void TemplateSimplifier::simplifyTemplates( // remove out of line member functions while (!mMemberFunctionsToDelete.empty()) { - removeTemplate(mMemberFunctionsToDelete.begin()->token); - mTemplateDeclarations.remove(mMemberFunctionsToDelete.front()); + const std::list::iterator it = std::find_if(mTemplateDeclarations.begin(), + mTemplateDeclarations.end(), + FindToken(mMemberFunctionsToDelete.begin()->token)); + // multiple functions can share the same declaration so make sure it hasn't already been deleted + if (it != mTemplateDeclarations.end()) { + removeTemplate(it->token); + mTemplateDeclarations.erase(it); + } mMemberFunctionsToDelete.erase(mMemberFunctionsToDelete.begin()); } }