Merge pull request #244 from simartin/ticket_5506
Ticket #5506: Don't crash upon invalid template declaration
This commit is contained in:
commit
aec3f18d77
|
@ -443,9 +443,10 @@ std::list<Token *> TemplateSimplifier::getTemplateDeclarations(Token *tokens, bo
|
||||||
tok = tok->linkAt(2);
|
tok = tok->linkAt(2);
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, "template <")) {
|
if (Token::simpleMatch(tok, "template <")) {
|
||||||
|
Token *parmEnd = tok->next()->findClosingBracket();
|
||||||
codeWithTemplates = true;
|
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
|
// Just a declaration => ignore this
|
||||||
if (tok2->str() == ";")
|
if (tok2->str() == ";")
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -61,6 +61,7 @@ private:
|
||||||
TEST_CASE(tokenize26); // #4245 (segmentation fault)
|
TEST_CASE(tokenize26); // #4245 (segmentation fault)
|
||||||
TEST_CASE(tokenize27); // #4525 (segmentation fault)
|
TEST_CASE(tokenize27); // #4525 (segmentation fault)
|
||||||
TEST_CASE(tokenize28); // #4725 (writing asm() around "^{}")
|
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
|
// don't freak out when the syntax is wrong
|
||||||
TEST_CASE(wrong_syntax1);
|
TEST_CASE(wrong_syntax1);
|
||||||
|
@ -825,6 +826,11 @@ private:
|
||||||
ASSERT_EQUALS("; asm ( \"voidf^{return}intmain\" ) ; ( ) { }", tokenizeAndStringify("; void f ^ { return } int main ( ) { }"));
|
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() {
|
void wrong_syntax1() {
|
||||||
{
|
{
|
||||||
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");
|
||||||
|
|
Loading…
Reference in New Issue