From c483bcb12bd9799d50e793974d38cf9b41fcb8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 22 Oct 2018 00:28:09 +0200 Subject: [PATCH] Fixed testrunner --- lib/tokenize.cpp | 12 ++++++++++++ test/testgarbage.cpp | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 664b4ad3e..9fe7804aa 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8401,6 +8401,18 @@ static const Token *findUnmatchedTernaryOp(const Token * const begin, const Toke void Tokenizer::findGarbageCode() const { + // Inside [] there can't be ; or various keywords + for (const Token *tok = tokens(); tok; tok = tok->next()) { + if (tok->str() != "[") + continue; + for (const Token *inner = tok->next(); inner != tok->link(); inner = inner->next()) { + if (Token::Match(inner, "(|[")) + inner = inner->link(); + else if (Token::Match(inner, ";|goto|return|typedef")) + syntaxError(inner); + } + } + 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(), "%name%|:|;|{|}|(|)|,")) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 26267332b..ce63f0dc2 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -782,7 +782,7 @@ private: } void garbageCode91() { // #6791 - checkCode("typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] }"); // do not crash + ASSERT_THROW(checkCode("typedef __attribute__((vector_size (16))) { return[ (v2df){ } ;] }"), InternalError); // throw syntax error } void garbageCode92() { // #6792 @@ -799,7 +799,7 @@ private: } void garbageCode96() { // #6807 - ASSERT_THROW(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;"), InternalError); + ASSERT_THROW(checkCode("typedef J J[ ; typedef ( ) ( ) { ; } typedef J J ;] ( ) ( J cx ) { n } ;"), InternalError); // throw syntax error } void garbageCode97() { // #6808