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"