From b9835fd4f90e4c986bb4fa92750c322bac4e8678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 15 Nov 2019 21:20:41 +0100 Subject: [PATCH] Fixed #9445 (Syntax error on typeof word in C) --- lib/tokenize.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index aaf8dd576..32aac8bb0 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9406,8 +9406,16 @@ void Tokenizer::findGarbageCode() const if (Token::Match(tok, "> %cop%")) continue; } - if (Token::Match(tok, "%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|++|--|::|sizeof|throw|decltype|typeof {|if|else|try|catch|while|do|for|return|switch|break|namespace")) - syntaxError(tok); + { + bool match1 = Token::Match(tok, "%or%|%oror%|==|!=|+|-|/|!|>=|<=|~|^|++|--|::|sizeof"); + bool match2 = Token::Match(tok->next(), "{|if|else|while|do|for|return|switch|break"); + if (isCPP()) { + match1 = match1 || Token::Match(tok, "::|throw|decltype|typeof"); + match2 = match2 || Token::Match(tok->next(), "try|catch|namespace"); + } + if (match1 && match2) + syntaxError(tok); + } if (Token::Match(tok, "( %any% )") && tok->next()->isKeyword() && !Token::simpleMatch(tok->next(), "void")) syntaxError(tok); if (Token::Match(tok, "%num%|%bool%|%char%|%str% %num%|%bool%|%char%|%str%") && !Token::Match(tok, "%str% %str%"))