Tokenizer::findGarbageCode: Make it less picky about 'UNKNOWN_MACRO if ..'

This commit is contained in:
Daniel Marjamäki 2016-07-26 14:35:11 +02:00
parent ba6478e98a
commit 71f62950ed
3 changed files with 6 additions and 5 deletions

View File

@ -8087,7 +8087,7 @@ const Token * Tokenizer::findGarbageCode() const
{
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
if (tok->previous() && !Token::Match(tok->previous(), ":|;|{|}|(|)|,|else|do"))
if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|(|)|,"))
return tok;
if (Token::Match(tok->previous(), "[(,]"))
continue;

View File

@ -1228,7 +1228,7 @@ private:
}
void garbageCode151() { // #4175
ASSERT_THROW(checkCode(">{ x while (y) z int = }"), InternalError);
checkCode(">{ x while (y) z int = }");
checkCode("void f() {\n" // #4911 - bad simplification => don't crash
" int a;\n"
" do { a=do_something() } while (a);\n"

View File

@ -1152,8 +1152,8 @@ private:
void ifAddBraces15() {
// ticket #2616 - unknown macro before if
// TODO: Move to TestGarbage
ASSERT_THROW(tokenizeAndStringify("{A if(x)y();}", false), InternalError);
// TODO: Remove "A" or change it to ";A;". Then cleanup Tokenizer::ifAddBraces().
ASSERT_EQUALS("{ A if ( x ) { y ( ) ; } }", tokenizeAndStringify("{A if(x)y();}", false));
}
void ifAddBraces16() {
@ -8388,10 +8388,11 @@ private:
// before if|for|while|switch
ASSERT_NO_THROW(tokenizeAndStringify("void f() { do switch (a) {} while (1); }"))
ASSERT_NO_THROW(tokenizeAndStringify("void f() { label: switch (a) {} }"));
ASSERT_NO_THROW(tokenizeAndStringify("void f() { UNKNOWN_MACRO if (a) {} }"))
// TODO ASSERT_NO_THROW(tokenizeAndStringify("void f() { MACRO(switch); }"));
// TODO ASSERT_NO_THROW(tokenizeAndStringify("void f() { MACRO(x,switch); }"));
// after (expr)
ASSERT_NO_THROW(tokenizeAndStringify("void f() { switch (a) int b; }"));
}
};