From e77effd0fcc5f88c08d3bfa23f2db15595d9316e Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 21 Jun 2023 15:15:19 +0200 Subject: [PATCH 1/2] Fix #11785 Syntax error: typedef not first keyword in statement --- lib/tokenize.cpp | 3 ++- test/testtokenize.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 15af853aaed..351d4833a3e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8239,7 +8239,8 @@ void Tokenizer::findGarbageCode() const prev = prev->previous(); if (Token::Match(prev, "%op%|%num%|%str%|%char%")) { if (!Token::simpleMatch(tok->tokAt(-2), "operator \"\" if") && - !Token::simpleMatch(tok->tokAt(-2), "extern \"C\"")) + !Token::simpleMatch(tok->tokAt(-2), "extern \"C\"") && + !Token::simpleMatch(prev, "> typedef")) syntaxError(tok, prev == tok->previous() ? (prev->str() + " " + tok->str()) : (prev->str() + " .. " + tok->str())); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index b9f66926ce2..865a744ff3c 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6920,6 +6920,8 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("template constexpr int n = 1;\n" "template T a[n];\n")); + ASSERT_NO_THROW(tokenizeAndStringify("std::vector typedef v;\n")); // #11785 + // op op ASSERT_THROW_EQUALS(tokenizeAndStringify("void f() { dostuff (x==>y); }"), InternalError, "syntax error: == >"); From e0a6df8e7767704e6bfe1e66ac6d05cfe192e091 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 21 Jun 2023 17:13:00 +0200 Subject: [PATCH 2/2] Extend test --- test/testtokenize.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 865a744ff3c..43b8d1c6b4b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6920,7 +6920,8 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("template constexpr int n = 1;\n" "template T a[n];\n")); - ASSERT_NO_THROW(tokenizeAndStringify("std::vector typedef v;\n")); // #11785 + ASSERT_EQUALS("std :: vector < int > x ;", // #11785 + tokenizeAndStringify("std::vector typedef v; v x;\n")); // op op