Skip to content

Commit e1a6600

Browse files
Fix #14429 FP uninitMemberVar for function declaration (danmar#8156)
1 parent d0524c3 commit e1a6600

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/tokenize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3349,12 +3349,14 @@ bool Tokenizer::simplifyUsing()
33493349
}
33503350
} else if (fpArgList && fpQual && Token::Match(tok1->next(), "%name%")) {
33513351
// function pointer
3352+
const bool isFuncDecl = Token::simpleMatch(tok1->tokAt(2), "(");
33523353
TokenList::copyTokens(tok1->next(), fpArgList, usingEnd->previous());
33533354
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
33543355
Token* leftPar = copyEnd->previous();
33553356
while (leftPar->str() != "(")
33563357
leftPar = leftPar->previous();
3357-
Token* const rightPar = copyEnd->next()->insertToken(")");
3358+
Token* const insertTok = isFuncDecl ? copyEnd->linkAt(2) : copyEnd->next();
3359+
Token* const rightPar = insertTok->insertToken(")");
33583360
Token::createMutualLinks(leftPar, rightPar);
33593361
tok1->deleteThis();
33603362
substitute = true;

test/testsimplifyusing.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,13 +899,19 @@ class TestSimplifyUsing : public TestFixture {
899899
ASSERT_EQUALS(expected2, tok(code2));
900900
ASSERT_EQUALS("", errout_str());
901901

902-
const char code3[] = "using FP = std::string (*)();\n"
902+
const char code3[] = "using FP = std::string (*)();\n" // #14421
903903
"using FPC = std::string (*const)();\n"
904904
"FP fp;\n"
905905
"FPC fpc{};\n";
906906
const char expected3[] = "std :: string ( * fp ) ( ) ; std :: string ( * const fpc ) ( ) { } ;";
907907
ASSERT_EQUALS(expected3, tok(code3));
908908
ASSERT_EQUALS("", errout_str());
909+
910+
const char code4[] = "using F = void(*)(char);\n" // #14429
911+
"F f(int);\n";
912+
const char expected4[] = "void * f ( char ) ;";
913+
ASSERT_EQUALS(expected4, tok(code4));
914+
ASSERT_EQUALS("", errout_str());
909915
}
910916

911917
void simplifyUsing8970() {

0 commit comments

Comments
 (0)