From dee703c6febba57831218a1129163671b881e52a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 17 Jun 2025 09:01:43 +0200 Subject: [PATCH 1/2] add test --- test/testnullpointer.cpp | 12 ++++++++++++ test/testtokenize.cpp | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 667f25aa8cb..43b34dfab28 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -141,6 +141,7 @@ class TestNullPointer : public TestFixture { TEST_CASE(nullpointer102); TEST_CASE(nullpointer103); TEST_CASE(nullpointer104); // #13881 + TEST_CASE(nullpointer105); // #13861 TEST_CASE(nullpointer_addressOf); // address of TEST_CASE(nullpointerSwitch); // #2626 TEST_CASE(nullpointer_cast); // #4692 @@ -2929,6 +2930,17 @@ class TestNullPointer : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void nullpointer105() // #13861 + { + check("struct AB { int a; int b; };\n" + "namespace ns { typedef AB S[10]; }\n" + "void foo(void) {\n" + " ns::S x = {0};\n" + " x[1].a = 2;\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); + } + void nullpointer_addressOf() { // address of check("void f() {\n" " struct X *x = 0;\n" diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6f529ae41f2..c2781a1fb03 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -81,6 +81,7 @@ class TestTokenizer : public TestFixture { TEST_CASE(tokenize39); // #9771 TEST_CASE(tokenize40); // #13181 TEST_CASE(tokenize41); // #13847 + TEST_CASE(tokenize42); // #13861 TEST_CASE(validate); @@ -878,6 +879,22 @@ class TestTokenizer : public TestFixture { (void)errout_str(); } + void tokenize42() { // #13861 + const char code[] = "struct AB { int a; int b; };\n" + "namespace ns { typedef AB S[10]; }\n" + "void foo(void) {\n" + " ns::S x = {0};\n" + " x[1].a = 2;\n" + "}\n"; + ASSERT_EQUALS("struct AB { int a ; int b ; } ;\n" + "\n" + "void foo ( ) {\n" + "AB x [ 10 ] = { 0 } ;\n" + "x [ 1 ] . a = 2 ;\n" + "}", tokenizeAndStringify(code)); + (void)errout_str(); + } + void validate() { // C++ code in C file ASSERT_THROW_INTERNAL(tokenizeAndStringify(";using namespace std;",false,Platform::Type::Native,false), SYNTAX); From 49443ca4938aa7e8bb7ffb02cd1878d450641baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Mon, 16 Jun 2025 17:01:56 +0200 Subject: [PATCH 2/2] fix #13861 --- lib/tokenize.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index bef31164cae..61a375631c5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2257,6 +2257,9 @@ void Tokenizer::simplifyTypedefCpp() if (!tok2->next()) syntaxError(tok2); + if (Token::Match(tok2, "] ; %name% = {") && tok2->next()->isSplittedVarDeclEq()) + tok2->deleteNext(2); + if (tok2->str() == "=") { if (tok2->strAt(1) == "{") tok2 = tok2->linkAt(1)->next();