From b1395b7fc989c5fd5981ccd0848ca9f189a7e085 Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 26 Jun 2023 15:00:25 +0200 Subject: [PATCH] Fix #11795 debug: simplifyUsing: unmatched body end --- 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 999f3b84a64..4969542f88f 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 1a6e2fde1d6..fb6c92bb9ce 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -72,6 +72,7 @@ class TestSimplifyUsing : public TestFixture { TEST_CASE(simplifyUsing25); TEST_CASE(simplifyUsing26); // #11090 TEST_CASE(simplifyUsing27); + TEST_CASE(simplifyUsing28); TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8971); @@ -675,6 +676,16 @@ class TestSimplifyUsing : public TestFixture { 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"