From 80c5cb6690c83f40c2b0d4409d472d329546e01d Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 25 Oct 2023 14:50:10 +0200 Subject: [PATCH] Fix #12008 debug: Executable scope 'x' with unknown function. (#5588) --- lib/tokenize.cpp | 2 +- test/testsimplifytypedef.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2fef09c0c62..0c1070b9a2f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1693,7 +1693,7 @@ void Tokenizer::simplifyTypedefCpp() } else { if (scope == 0 && !(classLevel > 1 && tok2 == spaceInfo[classLevel - 1].bodyEnd)) break; - --scope; + scope = std::max(scope - 1, 0); } } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index bebdd30b3f1..af51e0171dc 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -3395,6 +3395,18 @@ class TestSimplifyTypedef : public TestFixture { "void N::T::f(V*) {}\n" "namespace N {}\n"; ASSERT_EQUALS("namespace N { struct S { } ; struct T { void f ( int * ) ; } ; } void N :: T :: f ( int * ) { }", tok(code)); + + code = "namespace N {\n" // #12008 + " typedef char U;\n" + " typedef int V;\n" + " struct S {\n" + " S(V* v);\n" + " };\n" + "}\n" + "void f() {}\n" + "N::S::S(V* v) {}\n" + "namespace N {}\n"; + ASSERT_EQUALS("namespace N { struct S { S ( int * v ) ; } ; } void f ( ) { } N :: S :: S ( int * v ) { }", tok(code)); } void simplifyTypedef147() {