From 20cd0fc51b2dc177c5e05331858fc2ba4f4828a0 Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sat, 18 Jan 2020 18:58:33 +0100 Subject: [PATCH] Ticket #9572: Properly detect designated initializers. --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bc1c7d5ddeb..c6991785ba2 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9469,7 +9469,7 @@ void Tokenizer::findGarbageCode() const if (Token::simpleMatch(tok, ".") && !Token::simpleMatch(tok->previous(), ".") && !Token::simpleMatch(tok->next(), ".") && - !Token::Match(tok->previous(), "{|, . %name% [=.]") && + !Token::Match(tok->previous(), "{|, . %name% =|.|[") && !Token::Match(tok->previous(), ", . %name%")) { if (!Token::Match(tok->previous(), "%name%|)|]|>|}")) syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1)); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index a14468c82b6..538999f6593 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7968,6 +7968,12 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify("S s = { .ab.a=2, .ab.b=3 };")); ASSERT_NO_THROW(tokenizeAndStringify("extern \"C\" typedef void FUNC();")); + + // Ticket #9572 + ASSERT_NO_THROW(tokenizeAndStringify("struct poc { " + " struct { int d; } port[1]; " + "}; " + "struct poc p = { .port[0] = {.d = 3} };")); }