Fixed #5154 (Tokenizer: wrong handling of msvc 'for each')

This commit is contained in:
Daniel Marjamäki 2013-12-17 06:34:27 +01:00
parent 762806499f
commit e2bc99aa24
3 changed files with 14 additions and 5 deletions

View File

@ -1594,10 +1594,11 @@ bool Tokenizer::tokenize(std::istream &code,
// if MACRO
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "if|for|while|BOOST_FOREACH %var% (")) {
if (Token::simpleMatch(tok, "for each"))
// 'for each ( )' -> 'for ( )'
if (Token::simpleMatch(tok, "for each")) {
// 'for each ( )' -> 'asm ( )'
tok->str("asm");
tok->deleteNext();
else {
} else {
syntaxError(tok);
return false;
}

View File

@ -988,9 +988,9 @@ private:
}
void foreach() {
// #3690
// #3690,#5154
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()));
ASSERT_EQUALS("void f ( ) { asm ( \"char c in MyString\" ) { Console :: Write ( c ) ; } }" ,tokenizeAndStringify(code.c_str()));
}
void concatenateNegativeNumber() {

View File

@ -3097,6 +3097,14 @@ private:
" std::for_each(ints.begin(), ints.end(), [&x](int i){ x += i; });\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
// #5154 - MSVC 'for each'
functionVariableUsage("void f() {\n"
" std::map<int,int> ints;\n"
" ints[0]= 1;\n"
" for each(std::pair<int,int> i in ints) { x += i.first; }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarShift1() {