Skip to content

Commit 0a72cd3

Browse files
Fix #11795 debug: simplifyUsing: unmatched body end (#5198)
1 parent 9259aea commit 0a72cd3

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3251,7 +3251,7 @@ bool Tokenizer::simplifyUsing()
32513251
skip = true;
32523252
simplifyUsingError(usingStart, usingEnd);
32533253
}
3254-
tok1 = after;
3254+
tok1 = after->previous();
32553255
}
32563256

32573257
if (!skip)

test/testsimplifyusing.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class TestSimplifyUsing : public TestFixture {
7272
TEST_CASE(simplifyUsing25);
7373
TEST_CASE(simplifyUsing26); // #11090
7474
TEST_CASE(simplifyUsing27);
75+
TEST_CASE(simplifyUsing28);
7576

7677
TEST_CASE(simplifyUsing8970);
7778
TEST_CASE(simplifyUsing8971);
@@ -675,6 +676,16 @@ class TestSimplifyUsing : public TestFixture {
675676
ASSERT_EQUALS(expected, tok(code));
676677
}
677678

679+
void simplifyUsing28() { // #11795
680+
const char code[] = "void f() {\n"
681+
" using T = int;\n"
682+
" T* p{ new T };\n"
683+
"}\n";
684+
const char expected[] = "void f ( ) { int * p { new int } ; }";
685+
ASSERT_EQUALS(expected, tok(code, cppcheck::Platform::Type::Native, /*debugwarnings*/ true));
686+
ASSERT_EQUALS("", errout.str());
687+
}
688+
678689
void simplifyUsing8970() {
679690
const char code[] = "using V = std::vector<int>;\n"
680691
"struct A {\n"

0 commit comments

Comments
 (0)