Fixed #4465 (syntax error on valid C++ source file)

This commit is contained in:
Daniel Marjamäki 2013-03-14 18:52:22 +01:00
parent fe046a3350
commit 369e80b021
2 changed files with 23 additions and 9 deletions

View File

@ -68,21 +68,17 @@ const Token* TemplateSimplifier::hasComplicatedSyntaxErrorsInTemplates(Token *to
{
// check for more complicated syntax errors when using templates..
for (const Token *tok = tokens; tok; tok = tok->next()) {
// skip executing scopes (ticket #3183)..
if (Token::simpleMatch(tok, "( {"))
tok = tok->link();
// skip executing scopes..
if (Token::simpleMatch(tok, ") {") || Token::Match(tok, ") %var% {") || Token::Match(tok, "[,=] {")) {
if (Token::simpleMatch(tok, ") {") || Token::Match(tok, ") %var% {") || Token::Match(tok, "[;,=] {")) {
while (tok->str() != "{")
tok = tok->next();
tok = tok->link();
}
// skip executing scopes (ticket #1984)..
else if (Token::simpleMatch(tok, "; {"))
tok = tok->next()->link();
// skip executing scopes (ticket #3183)..
else if (Token::simpleMatch(tok, "( {"))
tok = tok->next()->link();
// skip executing scopes (ticket #1985)..
else if (Token::simpleMatch(tok, "try {")) {
tok = tok->next()->link();

View File

@ -5830,6 +5830,24 @@ private:
tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("[test.cpp:2]: (error) syntax error\n", errout.str());
}
// code is ok, don't show syntax error
{
errout.str("");
std::istringstream istr("struct A {int a;int b};\n"
"class Fred {"
"public:\n"
" Fred() : a({1,2}) {\n"
" for (int i=0;i<6;i++);\n" // <- no syntax error
" }\n"
"private:\n"
" A a;\n"
"};\n");
Settings settings;
Tokenizer tokenizer(&settings, this);
tokenizer.tokenize(istr, "test.cpp");
ASSERT_EQUALS("", errout.str());
}
}
void syntax_error_templates_2() {