Merge pull request #244 from simartin/ticket_5506

Ticket #5506: Don't crash upon invalid template declaration
This commit is contained in:
Daniel Marjamäki 2014-03-02 08:54:07 +01:00
commit aec3f18d77
2 changed files with 8 additions and 1 deletions

View File

@ -443,9 +443,10 @@ std::list<Token *> TemplateSimplifier::getTemplateDeclarations(Token *tokens, bo
tok = tok->linkAt(2);
if (Token::simpleMatch(tok, "template <")) {
Token *parmEnd = tok->next()->findClosingBracket();
codeWithTemplates = true;
for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) {
for (const Token *tok2 = parmEnd; tok2; tok2 = tok2->next()) {
// Just a declaration => ignore this
if (tok2->str() == ";")
break;

View File

@ -61,6 +61,7 @@ private:
TEST_CASE(tokenize26); // #4245 (segmentation fault)
TEST_CASE(tokenize27); // #4525 (segmentation fault)
TEST_CASE(tokenize28); // #4725 (writing asm() around "^{}")
TEST_CASE(tokenize29); // #5506 (segmentation fault upon invalid code)
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax1);
@ -825,6 +826,11 @@ private:
ASSERT_EQUALS("; asm ( \"voidf^{return}intmain\" ) ; ( ) { }", tokenizeAndStringify("; void f ^ { return } int main ( ) { }"));
}
// #5506 - segmentation fault upon invalid code
void tokenize29() {
tokenizeAndStringify("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;");
}
void wrong_syntax1() {
{
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");