template simplifier: fix syntax error (#2218)
This commit is contained in:
parent
d7d22f51b7
commit
4475c4c7e2
|
@ -419,7 +419,7 @@ unsigned int TemplateSimplifier::templateParameters(const Token *tok)
|
||||||
if (Token::Match(tok->previous(), "%var% <"))
|
if (Token::Match(tok->previous(), "%var% <"))
|
||||||
return 0;
|
return 0;
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
if (tok->str() == ">")
|
if (!tok || tok->str() == ">")
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
unsigned int level = 0;
|
unsigned int level = 0;
|
||||||
|
@ -3505,9 +3505,6 @@ void TemplateSimplifier::simplifyTemplates(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// split ">>" into "> >"
|
|
||||||
fixAngleBrackets();
|
|
||||||
|
|
||||||
// Remove "typename" unless used in template arguments or using type alias..
|
// Remove "typename" unless used in template arguments or using type alias..
|
||||||
for (Token *tok = mTokenList.front(); tok; tok = tok->next()) {
|
for (Token *tok = mTokenList.front(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "typename %name%") && !Token::Match(tok->tokAt(-3), "using %name% ="))
|
if (Token::Match(tok, "typename %name%") && !Token::Match(tok->tokAt(-3), "using %name% ="))
|
||||||
|
|
|
@ -4260,6 +4260,10 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
|
||||||
// Remove __asm..
|
// Remove __asm..
|
||||||
simplifyAsm();
|
simplifyAsm();
|
||||||
|
|
||||||
|
// foo < bar < >> => foo < bar < > >
|
||||||
|
if (isCPP())
|
||||||
|
mTemplateSimplifier->fixAngleBrackets();
|
||||||
|
|
||||||
// Bail out if code is garbage
|
// Bail out if code is garbage
|
||||||
if (mTimerResults) {
|
if (mTimerResults) {
|
||||||
Timer t("Tokenizer::tokenize::findGarbageCode", mSettings->showtime, mTimerResults);
|
Timer t("Tokenizer::tokenize::findGarbageCode", mSettings->showtime, mTimerResults);
|
||||||
|
|
|
@ -185,6 +185,7 @@ private:
|
||||||
TEST_CASE(template145); // syntax error
|
TEST_CASE(template145); // syntax error
|
||||||
TEST_CASE(template146); // syntax error
|
TEST_CASE(template146); // syntax error
|
||||||
TEST_CASE(template147); // syntax error
|
TEST_CASE(template147); // syntax error
|
||||||
|
TEST_CASE(template148); // syntax error
|
||||||
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
|
TEST_CASE(template_specialization_1); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
|
||||||
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
|
TEST_CASE(template_specialization_2); // #7868 - template specialization template <typename T> struct S<C<T>> {..};
|
||||||
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
|
TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template)
|
||||||
|
@ -3532,6 +3533,16 @@ private:
|
||||||
ASSERT_EQUALS(exp, tok(code));
|
ASSERT_EQUALS(exp, tok(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void template148() { // syntax error
|
||||||
|
const char code[] = "static_assert(var<S1<11, 100>> == var<S1<199, 23>> / 2\n"
|
||||||
|
" && var<S1<50, 120>> == var<S1<150, var<S1<10, 10>>>>\n"
|
||||||
|
" && var<S1<53, 23>> != 222, \"\");";
|
||||||
|
const char exp[] = "static_assert ( var < S1 < 11 , 100 > > == var < S1 < 199 , 23 > > / 2 "
|
||||||
|
"&& var < S1 < 50 , 120 > > == var < S1 < 150 , var < S1 < 10 , 10 > > > > "
|
||||||
|
"&& var < S1 < 53 , 23 > > != 222 , \"\" ) ;";
|
||||||
|
ASSERT_EQUALS(exp, tok(code));
|
||||||
|
}
|
||||||
|
|
||||||
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
|
void template_specialization_1() { // #7868 - template specialization template <typename T> struct S<C<T>> {..};
|
||||||
const char code[] = "template <typename T> struct C {};\n"
|
const char code[] = "template <typename T> struct C {};\n"
|
||||||
"template <typename T> struct S {a};\n"
|
"template <typename T> struct S {a};\n"
|
||||||
|
|
Loading…
Reference in New Issue