From 7e0fc4fb003a64df67c6b0030189d03950641f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 14 Nov 2019 21:18:31 +0100 Subject: [PATCH] Tokenizer: Detect more syntax errors when operator does not have operands --- lib/tokenize.cpp | 2 ++ test/testgarbage.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 354daf99e..a4b00bce7 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9439,6 +9439,8 @@ void Tokenizer::findGarbageCode() const if (!Token::Match(tok->next(), "%name%|*|~")) syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1)); } + if (Token::Match(tok, "[!|+-/%^~] )|]")) + syntaxError(tok); } // ternary operator without : diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 5254d4e86..001db7723 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1010,7 +1010,7 @@ private: } void garbageCode132() { // #7022 - checkCode("() () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () }"); + ASSERT_THROW(checkCode("() () { } { () () ({}) i() } void i(void(*ptr) ()) { ptr(!) () }"), InternalError); } void garbageCode133() { @@ -1247,7 +1247,7 @@ private: } void garbageCode159() { // #7119 - checkCode("({}typedef typename x;typename x!){({{}()})}"); // don't hang + ASSERT_THROW(checkCode("({}typedef typename x;typename x!){({{}()})}"), InternalError); } void garbageCode160() { // #7190