Skip to content

Commit 5d0671c

Browse files
committed
Fix #14421 Crash in TokenList::isFunctionHead()
1 parent bb8a593 commit 5d0671c

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

lib/tokenize.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,10 +3342,11 @@ bool Tokenizer::simplifyUsing()
33423342
} else if (fpArgList && fpQual && Token::Match(tok1->next(), "%name%")) {
33433343
// function pointer
33443344
TokenList::copyTokens(tok1->next(), fpArgList, usingEnd->previous());
3345-
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
3346-
tok1->deleteThis();
3345+
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
3346+
Token* const leftPar = copyEnd->tokAt(copyEnd->strAt(-1) == "(" ? -1 : -2);
33473347
Token* const rightPar = copyEnd->next()->insertToken(")");
3348-
Token::createMutualLinks(tok1->next(), rightPar);
3348+
Token::createMutualLinks(leftPar, rightPar);
3349+
tok1->deleteThis();
33493350
substitute = true;
33503351
} else if (fpArgList && !fpQual && Token::Match(tok1->next(), "* const| %name%")) {
33513352
// function pointer

test/testsimplifyusing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,14 @@ class TestSimplifyUsing : public TestFixture {
898898
const char expected2[] = "int ( * fp1 ) ( int ) ; int ( * const fp2 ) ( int ) ;";
899899
ASSERT_EQUALS(expected2, tok(code2));
900900
ASSERT_EQUALS("", errout_str());
901+
902+
const char code3[] = "using FP = std::string (*)();\n"
903+
"using FPC = std::string (*const)();\n"
904+
"FP fp;\n"
905+
"FPC fpc;\n";
906+
const char expected3[] = "std :: string ( * fp ) ( ) ; std :: string ( * const fpc ) ( ) ;";
907+
ASSERT_EQUALS(expected3, tok(code3));
908+
ASSERT_EQUALS("", errout_str());
901909
}
902910

903911
void simplifyUsing8970() {

0 commit comments

Comments
 (0)