Ticket #9572: Properly detect designated initializers. (#2496)

This commit is contained in:
Simon Martin 2020-01-25 10:14:16 +01:00 committed by Daniel Marjamäki
parent 569523bbef
commit 224a41361d
2 changed files with 7 additions and 1 deletions

View File

@ -9469,7 +9469,7 @@ void Tokenizer::findGarbageCode() const
if (Token::simpleMatch(tok, ".") && if (Token::simpleMatch(tok, ".") &&
!Token::simpleMatch(tok->previous(), ".") && !Token::simpleMatch(tok->previous(), ".") &&
!Token::simpleMatch(tok->next(), ".") && !Token::simpleMatch(tok->next(), ".") &&
!Token::Match(tok->previous(), "{|, . %name% [=.]") && !Token::Match(tok->previous(), "{|, . %name% =|.|[") &&
!Token::Match(tok->previous(), ", . %name%")) { !Token::Match(tok->previous(), ", . %name%")) {
if (!Token::Match(tok->previous(), "%name%|)|]|>|}")) if (!Token::Match(tok->previous(), "%name%|)|]|>|}"))
syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1)); syntaxError(tok, tok->strAt(-1) + " " + tok->str() + " " + tok->strAt(1));

View File

@ -7968,6 +7968,12 @@ private:
ASSERT_NO_THROW(tokenizeAndStringify("S s = { .ab.a=2, .ab.b=3 };")); ASSERT_NO_THROW(tokenizeAndStringify("S s = { .ab.a=2, .ab.b=3 };"));
ASSERT_NO_THROW(tokenizeAndStringify("extern \"C\" typedef void FUNC();")); 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} };"));
} }