Skip to content

Commit 450ea7c

Browse files
Fix #11899 FP unusedScopedObject for function call and imported constructor (danmar#6620)
1 parent 7964357 commit 450ea7c

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ void Tokenizer::simplifyUsingToTypedef()
571571
while (Token::Match(endtok, ":: %name%"))
572572
endtok = endtok->tokAt(2);
573573
if (endtok && endtok->str() == ";") {
574+
if (endtok->strAt(-1) == endtok->strAt(-3))
575+
continue;
574576
tok->next()->str("typedef");
575577
endtok = endtok->previous();
576578
endtok->insertToken(endtok->str());

test/testsimplifyusing.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class TestSimplifyUsing : public TestFixture {
7070
TEST_CASE(simplifyUsing28);
7171
TEST_CASE(simplifyUsing29);
7272
TEST_CASE(simplifyUsing30);
73+
TEST_CASE(simplifyUsing31);
7374

7475
TEST_CASE(simplifyUsing8970);
7576
TEST_CASE(simplifyUsing8971);
@@ -754,6 +755,33 @@ class TestSimplifyUsing : public TestFixture {
754755
}
755756
}
756757

758+
void simplifyUsing31() { // #11899
759+
const char code[] = "struct B {\n"
760+
" B();\n"
761+
" void f();\n"
762+
"};\n"
763+
"struct D : B {\n"
764+
" using B::B;\n"
765+
" void g() {\n"
766+
" B::f();\n"
767+
" }\n"
768+
" B b;\n"
769+
"};\n";
770+
const char expected[] = "struct B { "
771+
"B ( ) ; "
772+
"void f ( ) ; "
773+
"} ; "
774+
"struct D : B { "
775+
"using B = B :: B ; "
776+
"void g ( ) { "
777+
"B :: f ( ) ; "
778+
"} "
779+
"B b ; "
780+
"} ;";
781+
ASSERT_EQUALS(expected, tok(code, Platform::Type::Native, /*debugwarnings*/ true));
782+
ASSERT_EQUALS("", errout_str());
783+
}
784+
757785
void simplifyUsing8970() {
758786
const char code[] = "using V = std::vector<int>;\n"
759787
"struct A {\n"

0 commit comments

Comments
 (0)