From 6ed4d78a9c9e38dc409738fb83b3f2c456e4fc74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 1 Jun 2025 09:28:24 +0200 Subject: [PATCH 1/2] add test --- test/testtokenize.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 67e4f2d4162..a74006ed266 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -482,6 +482,8 @@ class TestTokenizer : public TestFixture { TEST_CASE(simplifyPlatformTypes); TEST_CASE(dumpFallthrough); + + TEST_CASE(simplifyRedundantParentheses); } #define tokenizeAndStringify(...) tokenizeAndStringify_(__FILE__, __LINE__, __VA_ARGS__) @@ -8556,6 +8558,14 @@ class TestTokenizer : public TestFixture { const std::string dump = ostr.str(); ASSERT(dump.find(" isAttributeFallthrough=\"true\"") != std::string::npos); } + + void simplifyRedundantParentheses() { + const char *code = "int f(struct S s) {\n" + " return g(1, &(int){ s.i });\n" + "}\n"; + SimpleTokenizer tokenizer(settingsDefault, *this, false); + ASSERT_NO_THROW(tokenizer.tokenize(code)); + } }; REGISTER_TEST(TestTokenizer) From 419edbbff3c9615006f84e7e8b64d88b775790f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Sun, 1 Jun 2025 09:21:54 +0200 Subject: [PATCH 2/2] fix 13833 --- lib/tokenize.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9c30590ff01..56afd47d671 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8033,7 +8033,7 @@ bool Tokenizer::simplifyRedundantParentheses() while (Token::Match(tok2, "%type%|static|const|extern") && tok2->str() != "operator") { tok2 = tok2->previous(); } - if (tok2 && !Token::Match(tok2, "[;,{]")) { + if (tok2 && !Token::Match(tok2, "[;{]")) { // Not a variable declaration } else { tok->deleteThis();