From a8efb5ce7d58ce3049a83047e45f94c03a0fed87 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 12 Nov 2024 12:15:59 +0100 Subject: [PATCH 1/2] Update testsimplifyusing.cpp --- test/testsimplifyusing.cpp | 65 +++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index a94fd50b835..18b0e4b2f14 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -73,6 +73,7 @@ class TestSimplifyUsing : public TestFixture { TEST_CASE(simplifyUsing31); TEST_CASE(simplifyUsing32); TEST_CASE(simplifyUsing33); + TEST_CASE(simplifyUsing34); TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8971); @@ -231,7 +232,7 @@ class TestSimplifyUsing : public TestFixture { const char expected[] = "void f ( ) " "{ " - "struct yy_buffer_state * state ; " + "yy_buffer_state * state ; " "}"; ASSERT_EQUALS(expected, tok(code)); @@ -311,13 +312,13 @@ class TestSimplifyUsing : public TestFixture { "struct t { int a ; } ; " "struct U { int a ; } ; " "struct Unnamed0 { int a ; } ; " - "struct s s ; " - "struct s * ps ; " - "struct t t ; " - "struct t * tp ; " - "struct U u ; " - "struct U * v ; " - "struct Unnamed0 * w ;"; + "s s ; " + "s * ps ; " + "t t ; " + "t * tp ; " + "U u ; " + "U * v ; " + "Unnamed0 * w ;"; ASSERT_EQUALS(expected, tok(code)); } @@ -342,13 +343,13 @@ class TestSimplifyUsing : public TestFixture { "union t { int a ; float b ; } ; " "union U { int a ; float b ; } ; " "union Unnamed0 { int a ; float b ; } ; " - "union s s ; " - "union s * ps ; " - "union t t ; " - "union t * tp ; " - "union U u ; " - "union U * v ; " - "union Unnamed0 * w ;"; + "s s ; " + "s * ps ; " + "t t ; " + "t * tp ; " + "U u ; " + "U * v ; " + "Unnamed0 * w ;"; ASSERT_EQUALS(expected, tok(code)); } @@ -361,8 +362,8 @@ class TestSimplifyUsing : public TestFixture { const char expected[] = "enum abc { a = 0 , b = 1 , c = 2 } ; " "enum xyz { x = 0 , y = 1 , z = 2 } ; " - "enum abc e1 ; " - "enum xyz e2 ;"; + "abc e1 ; " + "xyz e2 ;"; ASSERT_EQUALS(expected, tok(code)); } @@ -448,7 +449,7 @@ class TestSimplifyUsing : public TestFixture { const char expected[] = "struct STRFOO { " "char freem [ 4096 ] ; " "} ; " - "struct STRFOO s ;"; + "STRFOO s ;"; ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS("", errout_str()); @@ -470,10 +471,10 @@ class TestSimplifyUsing : public TestFixture { "class S2 : public C1 { } ; " "class S3 { } ; " "class S4 : public C1 { } ; " - "class S1 s1 ; " - "class S2 s2 ; " - "class S3 s3 ; " - "class S4 s4 ;"; + "S1 s1 ; " + "S2 s2 ; " + "S3 s3 ; " + "S4 s4 ;"; ASSERT_EQUALS(expected, tok(code)); } @@ -831,6 +832,26 @@ class TestSimplifyUsing : public TestFixture { ASSERT_EQUALS("", errout_str()); } + void simplifyUsing34() { // #13295 + const char code[] = "struct A {\n" + " static const int a = 1;\n" + "};\n" + "using B = struct A;\n" + "void g(int);\n" + "void f() {\n" + " g({ B::a });\n" + "}\n"; + const char expected[] = "struct A { " + "static const int a = 1 ; " + "} ; " + "void g ( int ) ; " + "void f ( ) { " + "g ( { A :: a } ) ; " + "}"; + ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true)); + ASSERT_EQUALS("", errout_str()); + } + void simplifyUsing8970() { const char code[] = "using V = std::vector;\n" "struct A {\n" From 23edaeea05b645124f9288f3a303c15f7b07f52d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 12 Nov 2024 12:17:06 +0100 Subject: [PATCH 2/2] Update tokenize.cpp --- lib/tokenize.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c00d98e47ac..6b215268a9f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3079,6 +3079,9 @@ bool Tokenizer::simplifyUsing() if (usingEnd) tok = usingEnd; + if (Token::Match(start, "class|struct|union|enum")) + start = start->next(); + // Unfortunately we have to start searching from the beginning // of the token stream because templates are instantiated at // the end of the token stream and it may be used before then.