diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2fef09c0c..0c1070b9a 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 bebdd30b3..af51e0171 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -3395,6 +3395,18 @@ private: "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() {