From d08aa666f680fd1ed6c2caa8dd6bb597d8552d4c Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Fri, 1 Feb 2019 00:59:49 -0500 Subject: [PATCH] template simplifier: fix crash on windows (#1639) * template simplifier: fix crash on windows Use right token when searching for template type alias to delete. * template simplifier: fix a cppcheck warning --- lib/templatesimplifier.cpp | 8 ++++---- test/testsimplifytemplate.cpp | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 887863bd1..421f8caf7 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1036,9 +1036,9 @@ void TemplateSimplifier::simplifyTemplateAliases() } // find declaration - const std::list::iterator it2 = std::find_if(mTemplateDeclarations.begin(), + const std::list::iterator it3 = std::find_if(mTemplateDeclarations.begin(), mTemplateDeclarations.end(), - FindToken(startToken ? startToken : mTokenList.front())); + FindToken(startToken ? startToken->next() : mTokenList.front())); if (startToken) eraseTokens(startToken, endToken); @@ -1048,8 +1048,8 @@ void TemplateSimplifier::simplifyTemplateAliases() } // remove declaration - if (it2 != mTemplateDeclarations.end()) - mTemplateDeclarations.erase(it2); + if (it3 != mTemplateDeclarations.end()) + mTemplateDeclarations.erase(it3); } } } diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 4492481d5..aceb3f4a0 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -1282,7 +1282,7 @@ private: tok(code); // don't crash } - void template65() { // #8321 + void template65() { // #8321 (crash) const char code[] = "namespace bpp\n" "{\n" "template\n" @@ -1298,7 +1298,18 @@ private: " AssociationDAGlobalGraphObserver grObs;\n" " return 1;\n" "}"; - tok(code); // don't crash + const char exp [] = "namespace bpp " + "{ " + "class AssociationDAGraphImplObserver ; " + "} " + "using namespace bpp ; " + "int main ( ) { " + "bpp :: AssociationDAGraphImplObserver grObs ; " + "return 1 ; " + "} class bpp :: AssociationDAGraphImplObserver : " + "public AssociationGraphImplObserver < std :: string , int , DAGlobalGraph > " + "{ } ;"; + ASSERT_EQUALS(exp, tok(code)); } void template66() { // #8725