From 71f62950edfd7d9b6eba495d1b74cfef0d1a4503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 26 Jul 2016 14:35:11 +0200 Subject: [PATCH] Tokenizer::findGarbageCode: Make it less picky about 'UNKNOWN_MACRO if ..' --- lib/tokenize.cpp | 2 +- test/testgarbage.cpp | 2 +- test/testtokenize.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9c44f595d..2a8b81f1e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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; diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 9dd57b557..4a1b10432 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -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" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 03f574de1..2e940887b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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; }")); } };