Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3343,9 +3343,12 @@ bool Tokenizer::simplifyUsing()
// function pointer
TokenList::copyTokens(tok1->next(), fpArgList, usingEnd->previous());
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
tok1->deleteThis();
Token* leftPar = copyEnd->previous();
while (leftPar->str() != "(")
leftPar = leftPar->previous();
Token* const rightPar = copyEnd->next()->insertToken(")");
Token::createMutualLinks(tok1->next(), rightPar);
Token::createMutualLinks(leftPar, rightPar);
tok1->deleteThis();
substitute = true;
} else if (fpArgList && !fpQual && Token::Match(tok1->next(), "* const| %name%")) {
// function pointer
Expand Down
8 changes: 8 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,14 @@ class TestSimplifyUsing : public TestFixture {
const char expected2[] = "int ( * fp1 ) ( int ) ; int ( * const fp2 ) ( int ) ;";
ASSERT_EQUALS(expected2, tok(code2));
ASSERT_EQUALS("", errout_str());

const char code3[] = "using FP = std::string (*)();\n"
"using FPC = std::string (*const)();\n"
"FP fp;\n"
"FPC fpc{};\n";
const char expected3[] = "std :: string ( * fp ) ( ) ; std :: string ( * const fpc ) ( ) { } ;";
ASSERT_EQUALS(expected3, tok(code3));
ASSERT_EQUALS("", errout_str());
}

void simplifyUsing8970() {
Expand Down
Loading