From 22f01f035c59fc0e8b96b2bb288b3e4e2c28cb8a Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Wed, 27 Mar 2019 16:42:50 -0400 Subject: [PATCH] Fixed #9042 (Another `using BOOL` type breach) (#1765) --- lib/tokenize.cpp | 4 ++-- test/testpostfixoperator.cpp | 10 ++++++++++ test/testsimplifyusing.cpp | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fd9fab835..c0f268dee 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1899,6 +1899,7 @@ bool Tokenizer::simplifyUsing() } if (tok == endOfTemplateDefinition) { inTemplateDefinition = false; + endOfTemplateDefinition = nullptr; continue; } } @@ -2127,7 +2128,6 @@ bool Tokenizer::simplifyUsing() str += " ;"; std::list callstack(1, usingStart); mErrorLogger->reportErr(ErrorLogger::ErrorMessage(callstack, &list, Severity::debug, "debug", - "Failed to parse \'" + str + "\'. The checking continues anyway.", false)); } } @@ -2148,7 +2148,7 @@ bool Tokenizer::simplifyUsing() if (usingEnd->next()) Token::eraseTokens(usingStart->previous(), usingEnd->next()); else { - Token::eraseTokens(usingStart, usingEnd); + Token::eraseTokens(usingStart->previous(), usingEnd); usingEnd->deleteThis(); } } else { diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index a666b2e6e..07614cd29 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -173,6 +173,16 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // #9042 + check("template \n" + "class c {\n" + " int i = 0;\n" + " c() { i--; }\n" + "};\n" + "template \n" + "class s {};\n" + "using BOOL = char;"); + ASSERT_EQUALS("", errout.str()); } void testfor() { diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 84b60438c..7637e347f 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -63,6 +63,7 @@ private: TEST_CASE(simplifyUsing8971); TEST_CASE(simplifyUsing8976); TEST_CASE(simplifyUsing9040); + TEST_CASE(simplifyUsing9042); } std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) { @@ -474,6 +475,27 @@ private: ASSERT_EQUALS(exp, tok(code, true, Settings::Win64)); } + void simplifyUsing9042() { + const char code[] = "template \n" + "class c {\n" + " int i = 0;\n" + " c() { i--; }\n" + "};\n" + "template \n" + "class s {};\n" + "using BOOL = char;"; + + const char exp[] = "template < class T > " + "class c { " + "int i ; i = 0 ; " + "c ( ) { i -- ; } " + "} ; " + "template < class T > " + "class s { } ;"; + + ASSERT_EQUALS(exp, tok(code, true, Settings::Win64)); + } + }; REGISTER_TEST(TestSimplifyUsing)