Skip to content

Commit b6e1f45

Browse files
authored
Fix #14910: Wrong tokenization of qualified function-pointer member definition (#8718)
1 parent df67f2b commit b6e1f45

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

lib/tokenize.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,12 +3389,17 @@ bool Tokenizer::simplifyUsing()
33893389
} else if (fpArgList && fpQual && Token::Match(tok1->next(), "%name%")) {
33903390
// function pointer
33913391
const bool isFuncDecl = Token::simpleMatch(tok1->tokAt(2), "(");
3392-
TokenList::copyTokens(tok1->next(), fpArgList, usingEnd->previous());
3392+
Token *dest = tok1->next();
3393+
while (Token::Match(dest, "%name% :: %name%"))
3394+
dest = dest->tokAt(2);
3395+
TokenList::copyTokens(dest, fpArgList, usingEnd->previous());
33933396
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
33943397
Token* leftPar = copyEnd->previous();
33953398
while (leftPar->str() != "(")
33963399
leftPar = leftPar->previous();
3397-
Token* const insertTok = isFuncDecl ? copyEnd->linkAt(2) : copyEnd->next();
3400+
Token *insertTok = isFuncDecl ? copyEnd->linkAt(2) : copyEnd->next();
3401+
while (Token::Match(insertTok, "%name% :: %name%"))
3402+
insertTok = insertTok->tokAt(2);
33983403
Token* const rightPar = insertTok->insertToken(")");
33993404
Token::createMutualLinks(leftPar, rightPar);
34003405
tok1->deleteThis();

test/testsimplifyusing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class TestSimplifyUsing : public TestFixture {
7878
TEST_CASE(simplifyUsing38);
7979
TEST_CASE(simplifyUsing39);
8080
TEST_CASE(simplifyUsing40);
81+
TEST_CASE(simplifyUsing41);
8182

8283
TEST_CASE(simplifyUsing8970);
8384
TEST_CASE(simplifyUsing8971);
@@ -948,6 +949,13 @@ class TestSimplifyUsing : public TestFixture {
948949
ASSERT_EQUALS(expected, tok(code));
949950
}
950951

952+
void simplifyUsing41() {
953+
const char code[] = "using FpHandler = void(*)(const SourceLocation&);\n"
954+
"inline FpHandler AssertImpl::m_fpHandler = nullptr;\n";
955+
const char expected[] = "void ( * AssertImpl :: m_fpHandler ) ( const SourceLocation & ) ; m_fpHandler = nullptr ;";
956+
ASSERT_EQUALS(expected, tok(code));
957+
}
958+
951959
void simplifyUsing8970() {
952960
const char code[] = "using V = std::vector<int>;\n"
953961
"struct A {\n"

0 commit comments

Comments
 (0)