Tokenizer::findGarbageCode: Make it less picky about 'UNKNOWN_MACRO if ..'
This commit is contained in:
parent
ba6478e98a
commit
71f62950ed
|
@ -8087,7 +8087,7 @@ const Token * Tokenizer::findGarbageCode() const
|
||||||
{
|
{
|
||||||
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
for (const Token *tok = tokens(); tok; tok = tok->next()) {
|
||||||
if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... }
|
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;
|
return tok;
|
||||||
if (Token::Match(tok->previous(), "[(,]"))
|
if (Token::Match(tok->previous(), "[(,]"))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1228,7 +1228,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void garbageCode151() { // #4175
|
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
|
checkCode("void f() {\n" // #4911 - bad simplification => don't crash
|
||||||
" int a;\n"
|
" int a;\n"
|
||||||
" do { a=do_something() } while (a);\n"
|
" do { a=do_something() } while (a);\n"
|
||||||
|
|
|
@ -1152,8 +1152,8 @@ private:
|
||||||
|
|
||||||
void ifAddBraces15() {
|
void ifAddBraces15() {
|
||||||
// ticket #2616 - unknown macro before if
|
// ticket #2616 - unknown macro before if
|
||||||
// TODO: Move to TestGarbage
|
// TODO: Remove "A" or change it to ";A;". Then cleanup Tokenizer::ifAddBraces().
|
||||||
ASSERT_THROW(tokenizeAndStringify("{A if(x)y();}", false), InternalError);
|
ASSERT_EQUALS("{ A if ( x ) { y ( ) ; } }", tokenizeAndStringify("{A if(x)y();}", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifAddBraces16() {
|
void ifAddBraces16() {
|
||||||
|
@ -8388,10 +8388,11 @@ private:
|
||||||
// before if|for|while|switch
|
// before if|for|while|switch
|
||||||
ASSERT_NO_THROW(tokenizeAndStringify("void f() { do switch (a) {} while (1); }"))
|
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() { 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(switch); }"));
|
||||||
// TODO ASSERT_NO_THROW(tokenizeAndStringify("void f() { MACRO(x,switch); }"));
|
// TODO ASSERT_NO_THROW(tokenizeAndStringify("void f() { MACRO(x,switch); }"));
|
||||||
|
|
||||||
|
// after (expr)
|
||||||
ASSERT_NO_THROW(tokenizeAndStringify("void f() { switch (a) int b; }"));
|
ASSERT_NO_THROW(tokenizeAndStringify("void f() { switch (a) int b; }"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue