From 7eb1da9ffce999d1aa5c226ed7fa42729f6b6165 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 27 Jan 2023 08:19:32 +0100 Subject: [PATCH] Fix #11506 debug: simplifyUsing: unmatched body end (#4728) --- lib/tokenize.cpp | 2 +- test/testsimplifytypedef.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b9c75771a..16f2cadb1 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1360,7 +1360,7 @@ void Tokenizer::simplifyTypedef() const bool sameStartEnd = (typeStart == typeEnd); // check for derived class: class A : some_typedef { - const bool isDerived = Token::Match(tok2->previous(), "public|protected|private %type% {|,"); + const bool isDerived = Token::Match(tok2->previous(), "public|protected|private|: %type% {|,"); // check for cast: (some_typedef) A or static_cast(A) // todo: check for more complicated casts like: (const some_typedef *)A diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index abbb110f0..41b054234 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -189,6 +189,7 @@ private: TEST_CASE(simplifyTypedef140); // #10798 TEST_CASE(simplifyTypedef141); // #10144 TEST_CASE(simplifyTypedef142); // T() when T is a pointer type + TEST_CASE(simplifyTypedef143); // #11506 TEST_CASE(simplifyTypedef144); // #9353 TEST_CASE(simplifyTypedefFunction1); @@ -3071,6 +3072,16 @@ private: ASSERT_EQUALS("void f ( int * = ( int * ) 0 ) { }", tok(code2)); } + void simplifyTypedef143() { // #11506 + const char code[] = "typedef struct { int i; } B;\n" + "void f() {\n" + " struct D : B {\n" + " char c;\n" + " };\n" + "}\n"; + ASSERT_EQUALS("struct B { int i ; } ; void f ( ) { struct D : B { char c ; } ; }", tok(code)); + } + void simplifyTypedef144() { // #9353 const char code[] = "typedef struct {} X;\n" "std::vector v;\n";