From 315ce2e283943ef5e28e03719b85e684026ec855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 3 Dec 2026 15:20:19 +0100 Subject: [PATCH 1/2] test --- test/testtokenize.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 7a8d2512b4f..dcd1534a84f 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -490,6 +490,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(checkConfiguration); TEST_CASE(unknownMacroBeforeReturn); + TEST_CASE(unknownMacroBracedArgument); TEST_CASE(cppKeywordInCSource); @@ -8853,6 +8854,12 @@ class TestTokenizer : public TestFixture { ASSERT_THROW_INTERNAL(tokenizeAndStringify("int f() { X return 0; }\n"), UNKNOWN_MACRO); } + void unknownMacroBracedArgument() { + ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("F(a, { float y = p.y; return 0 });\n"), + UNKNOWN_MACRO, + "There is an unknown macro here somewhere. Configuration is required. If F is a macro then please configure it."); + } + void cppKeywordInCSource() { ASSERT_NO_THROW(tokenizeAndStringify("int throw() {}\n", dinit(TokenizeOptions, $.cpp = false))); From 771daae0cd41c1cf3e2fefad9593e3d39ea40437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 3 Dec 2026 15:20:38 +0100 Subject: [PATCH 2/2] fix --- lib/tokenize.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 72873ac2475..9969cd3b78c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8944,6 +8944,16 @@ void Tokenizer::findGarbageCode() const "typedef", "while" }; + const auto hasTopLevelSemicolon = [](const Token *brace) { + for (const Token *tok = brace->next(); tok && tok != brace->link(); tok = tok->next()) { + if (Token::Match(tok, "(|[|{") && tok->link()) + tok = tok->link(); + else if (tok->str() == ";") + return true; + } + return false; + }; + for (const Token *tok = tokens(); tok; tok = tok->next()) { // initialization: = { if (Token::simpleMatch(tok, "= {") && Token::simpleMatch(tok->linkAt(1), "} (")) @@ -8995,6 +9005,17 @@ void Tokenizer::findGarbageCode() const syntaxError(tok); } + if (Token::Match(tok, "(|, {") && !Token::Match(tok->linkAt(1)->previous(), ";|}") && hasTopLevelSemicolon(tok->next())) { + const Token *par = tok; + while (par && !Token::Match(par, "(|;|{")) { + if (Token::Match(par, ")|]|}")) + par = par->link(); + par = par->previous(); + } + if (par && par->str() == "(" && Token::Match(par->previous(), "%name% (") && !par->previous()->isKeyword()) + unknownMacroError(par->previous()); + } + if (tok->isControlFlowKeyword()) { if (Token::Match(tok, "if|while|for|switch")) { // if|while|for|switch (EXPR) { ... } if (tok->previous() && !Token::Match(tok->previous(), "%name%|:|;|{|}|)")) {