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
4 changes: 3 additions & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3341,12 +3341,14 @@ 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* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
Token* leftPar = copyEnd->previous();
while (leftPar->str() != "(")
leftPar = leftPar->previous();
Token* const rightPar = copyEnd->next()->insertToken(")");
Token* const insertTok = isFuncDecl ? copyEnd->linkAt(2) : copyEnd->next();
Token* const rightPar = insertTok->insertToken(")");
Token::createMutualLinks(leftPar, rightPar);
tok1->deleteThis();
substitute = true;
Expand Down
8 changes: 7 additions & 1 deletion test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,13 +899,19 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS(expected2, tok(code2));
ASSERT_EQUALS("", errout_str());

const char code3[] = "using FP = std::string (*)();\n"
const char code3[] = "using FP = std::string (*)();\n" // #14421
"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());

const char code4[] = "using F = void(*)(char);\n" // #14429
"F f(int);\n";
const char expected4[] = "void * f ( char ) ;";
ASSERT_EQUALS(expected4, tok(code4));
ASSERT_EQUALS("", errout_str());
}

void simplifyUsing8970() {
Expand Down
Loading