From 0a72cd3b729d0b1240e19ce98c199f33361f1c50 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 27 Jun 2023 15:45:25 +0200 Subject: [PATCH] Fix #11795 debug: simplifyUsing: unmatched body end (#5198) --- lib/tokenize.cpp | 2 +- test/testsimplifyusing.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 999f3b84a..4969542f8 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3251,7 +3251,7 @@ bool Tokenizer::simplifyUsing() skip = true; simplifyUsingError(usingStart, usingEnd); } - tok1 = after; + tok1 = after->previous(); } if (!skip) diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index 1a6e2fde1..fb6c92bb9 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -72,6 +72,7 @@ private: TEST_CASE(simplifyUsing25); TEST_CASE(simplifyUsing26); // #11090 TEST_CASE(simplifyUsing27); + TEST_CASE(simplifyUsing28); TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8971); @@ -675,6 +676,16 @@ private: ASSERT_EQUALS(expected, tok(code)); } + void simplifyUsing28() { // #11795 + const char code[] = "void f() {\n" + " using T = int;\n" + " T* p{ new T };\n" + "}\n"; + const char expected[] = "void f ( ) { int * p { new int } ; }"; + ASSERT_EQUALS(expected, tok(code, cppcheck::Platform::Type::Native, /*debugwarnings*/ true)); + ASSERT_EQUALS("", errout.str()); + } + void simplifyUsing8970() { const char code[] = "using V = std::vector;\n" "struct A {\n"