Fixed #9042 (Another `using BOOL` type breach) (#1765)

This commit is contained in:
IOBYTE 2019-03-27 16:42:50 -04:00 committed by Daniel Marjamäki
parent 0f6a90c595
commit 22f01f035c
3 changed files with 34 additions and 2 deletions

View File

@ -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<const Token *> 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 {

View File

@ -173,6 +173,16 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
// #9042
check("template <class T>\n"
"class c {\n"
" int i = 0;\n"
" c() { i--; }\n"
"};\n"
"template <class T>\n"
"class s {};\n"
"using BOOL = char;");
ASSERT_EQUALS("", errout.str());
}
void testfor() {

View File

@ -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 <class T>\n"
"class c {\n"
" int i = 0;\n"
" c() { i--; }\n"
"};\n"
"template <class T>\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)