Skip to content
Merged
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
9 changes: 7 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3389,12 +3389,17 @@ bool Tokenizer::simplifyUsing()
} else if (fpArgList && fpQual && Token::Match(tok1->next(), "%name%")) {
// function pointer
const bool isFuncDecl = Token::simpleMatch(tok1->tokAt(2), "(");
TokenList::copyTokens(tok1->next(), fpArgList, usingEnd->previous());
Token *dest = tok1->next();
while (Token::Match(dest, "%name% :: %name%"))
dest = dest->tokAt(2);
TokenList::copyTokens(dest, fpArgList, usingEnd->previous());
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
Token* leftPar = copyEnd->previous();
while (leftPar->str() != "(")
leftPar = leftPar->previous();
Token* const insertTok = isFuncDecl ? copyEnd->linkAt(2) : copyEnd->next();
Token *insertTok = isFuncDecl ? copyEnd->linkAt(2) : copyEnd->next();
while (Token::Match(insertTok, "%name% :: %name%"))
insertTok = insertTok->tokAt(2);
Token* const rightPar = insertTok->insertToken(")");
Token::createMutualLinks(leftPar, rightPar);
tok1->deleteThis();
Expand Down
8 changes: 8 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TestSimplifyUsing : public TestFixture {
TEST_CASE(simplifyUsing38);
TEST_CASE(simplifyUsing39);
TEST_CASE(simplifyUsing40);
TEST_CASE(simplifyUsing41);

TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971);
Expand Down Expand Up @@ -948,6 +949,13 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS(expected, tok(code));
}

void simplifyUsing41() {
const char code[] = "using FpHandler = void(*)(const SourceLocation&);\n"
"inline FpHandler AssertImpl::m_fpHandler = nullptr;\n";
const char expected[] = "void ( * AssertImpl :: m_fpHandler ) ( const SourceLocation & ) ; m_fpHandler = nullptr ;";
ASSERT_EQUALS(expected, tok(code));
}

void simplifyUsing8970() {
const char code[] = "using V = std::vector<int>;\n"
"struct A {\n"
Expand Down
Loading