From 3d4b773fd189b2647f6303735e1f7ddba4afd5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 22 Mar 2018 09:07:58 +0100 Subject: [PATCH] Fixed #8390 (Syntax error from an MSVC internal header) --- lib/tokenize.cpp | 24 +++++++++++++++++------- test/testgarbage.cpp | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5894d48dd..e1fed19a6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3272,13 +3272,14 @@ void Tokenizer::createLinks2() type.pop(); Token * const top2 = type.empty() ? nullptr : type.top(); type.push(top1); - if (token->str() == ">>" && (!top2 || top2->str() != "<")) - continue; - if (token->next() && - !Token::Match(token->next(), "%name%|>|&|&&|*|::|,|(|)|{|}|;|[|:") && - !Token::Match(token->next(), "&& %name% =")) - continue; - + if (!top2 || top2->str() != "<") { + if (token->str() == ">>") + continue; + if (token->next() && + !Token::Match(token->next(), "%name%|>|&|&&|*|::|,|(|)|{|}|;|[|:") && + !Token::Match(token->next(), "&& %name% =")) + continue; + } // if > is followed by [ .. "new a[" is expected if (token->strAt(1) == "[") { Token *prev = type.top()->previous(); @@ -8392,7 +8393,16 @@ void Tokenizer::findGarbageCode() const } // Operators without operands.. + const Token *templateEndToken = nullptr; for (const Token *tok = tokens(); tok; tok = tok->next()) { + if (!templateEndToken) { + if (tok->str() == "<" && isCPP()) + templateEndToken = tok->findClosingBracket(); + } else if (templateEndToken == tok) { + templateEndToken = nullptr; + } else if (Token::Match(tok, "> %cop%")) { + continue; + } if (Token::Match(tok, "%cop%|=|,|[ %or%|%oror%|/|%")) syntaxError(tok); if (Token::Match(tok, ";|(|[ %comp%")) diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index ba993ed4a..ae2c64b90 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -1455,6 +1455,8 @@ private: void garbageCode187() { // # 8152 - segfault in handling const std::string inp("0|\0|0>;\n", 8); ASSERT_THROW(checkCode(inp), InternalError); + + checkCode("template struct S : A< B || C > {};"); // No syntax error: #8390 } void garbageCode188() { // #8255