Skip to content

Commit eef2137

Browse files
Fix #14421 Crash in TokenList::isFunctionHead() (danmar#8146)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 8c762ad commit eef2137

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/tokenize.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,9 +3343,12 @@ bool Tokenizer::simplifyUsing()
33433343
// function pointer
33443344
TokenList::copyTokens(tok1->next(), fpArgList, usingEnd->previous());
33453345
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
3346-
tok1->deleteThis();
3346+
Token* leftPar = copyEnd->previous();
3347+
while (leftPar->str() != "(")
3348+
leftPar = leftPar->previous();
33473349
Token* const rightPar = copyEnd->next()->insertToken(")");
3348-
Token::createMutualLinks(tok1->next(), rightPar);
3350+
Token::createMutualLinks(leftPar, rightPar);
3351+
tok1->deleteThis();
33493352
substitute = true;
33503353
} else if (fpArgList && !fpQual && Token::Match(tok1->next(), "* const| %name%")) {
33513354
// 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)