Reverted 107b3b44. Write syntax error for 'if MACRO()'. We can't know if MACRO() is supposed to be used in the condition or if it is some annotation that should be removed. Ticket #4171

This commit is contained in:
Daniel Marjamäki 2012-10-06 19:12:39 +02:00
parent e3bbcf501f
commit 4c1abde48e
2 changed files with 6 additions and 20 deletions

View File

@ -1592,22 +1592,8 @@ bool Tokenizer::tokenize(std::istream &code,
// 'for each ( )' -> 'for ( )'
tok->deleteNext();
else {
// locate the ')' parenthesis (the Token::link is not set yet)
// Then replace 'if MACRO(X)' with 'if (MACRO(X))'
unsigned int parlevel = 0;
for (Token *tok2 = tok; tok2; tok2 = tok2->next()) {
if (tok2->str() == "(")
++parlevel;
else if (tok2->str() == ")") {
if (parlevel == 1) {
tok->insertToken("(");
tok2->insertToken(")");
}
if (parlevel <= 1)
break;
--parlevel;
}
}
syntaxError(tok);
return false;
}
}
}

View File

@ -709,10 +709,10 @@ private:
}
void wrong_syntax_if_macro() {
// #2518 and #4171
const char code[] = "void f() { if MACRO() { } }";
ASSERT_EQUALS("void f ( ) { if ( MACRO ( ) ) { } }", tokenizeAndStringify(code, false));
ASSERT_EQUALS("", errout.str());
// #2518
const std::string code("void f() { if MACRO(); }");
tokenizeAndStringify(code.c_str(), false);
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
}
void garbageCode() {