Tokenizer: added a workaround for #3690 (Support MSVC's 'for each').
This commit is contained in:
parent
6100776847
commit
6fd60eebb0
|
@ -1593,10 +1593,15 @@ bool Tokenizer::tokenize(std::istream &code,
|
|||
}
|
||||
|
||||
// if MACRO
|
||||
for (const Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, "if|for|while|BOOST_FOREACH %var% (")) {
|
||||
syntaxError(tok);
|
||||
return false;
|
||||
if (Token::simpleMatch(tok, "for each"))
|
||||
// 'for each ( )' -> 'for ( )'
|
||||
tok->deleteNext();
|
||||
else {
|
||||
syntaxError(tok);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,8 @@ private:
|
|||
TEST_CASE(wrong_syntax4); // #3618
|
||||
TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO()
|
||||
|
||||
TEST_CASE(foreach); // #3690
|
||||
|
||||
TEST_CASE(minus);
|
||||
|
||||
TEST_CASE(longtok);
|
||||
|
@ -706,6 +708,12 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||
}
|
||||
|
||||
void foreach() {
|
||||
// #3690
|
||||
const std::string code("void f() { for each ( char c in MyString ) { Console::Write(c); } }");
|
||||
ASSERT_EQUALS("void f ( ) { for ( char c in MyString ) { Console :: Write ( c ) ; } }" ,tokenizeAndStringify(code.c_str()));
|
||||
}
|
||||
|
||||
void minus() {
|
||||
ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12"));
|
||||
ASSERT_EQUALS("1 - 2", tokenizeAndStringify("1-2"));
|
||||
|
|
Loading…
Reference in New Issue