Skip to content

Commit 16fc50c

Browse files
Fix #10252 debug: Failed to parse 'x'. The checking continues anyway. (danmar#8129)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent ae060de commit 16fc50c

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ jobs:
716716
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1
717717
# check gui with qt settings
718718
mkdir b2
719-
./cppcheck $selfcheck_options $cppcheck_options $gui_options --cppcheck-build-dir=b2 --addon=naming.json --suppress=simplifyUsing:*/moc_*.cpp -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1
719+
./cppcheck $selfcheck_options $cppcheck_options $gui_options --cppcheck-build-dir=b2 --addon=naming.json -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1
720720
# self check test and tools
721721
./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1
722722
./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1

lib/tokenize.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,6 +3211,8 @@ bool Tokenizer::simplifyUsing()
32113211
}
32123212

32133213
Token * arrayStart = nullptr;
3214+
Token * fpArgList = nullptr;
3215+
Token * fpQual = nullptr;
32143216

32153217
// parse the type
32163218
Token *type = start;
@@ -3310,6 +3312,18 @@ bool Tokenizer::simplifyUsing()
33103312
} while (type && type->str() == "[");
33113313
}
33123314

3315+
// check for function pointer
3316+
if (type && type->str() == "(") {
3317+
if (Token::simpleMatch(type->link(), ") (")) {
3318+
fpArgList = type->link()->next();
3319+
fpQual = type;
3320+
type = type->link()->linkAt(1)->next();
3321+
} else if (type->link()->next() == usingEnd) {
3322+
fpArgList = type;
3323+
type = usingEnd;
3324+
}
3325+
}
3326+
33133327
// make sure we are in a good state
33143328
if (!tok1 || !tok1->next())
33153329
break; // bail
@@ -3325,6 +3339,24 @@ bool Tokenizer::simplifyUsing()
33253339
tok1->deleteThis();
33263340
substitute = true;
33273341
}
3342+
} else if (fpArgList && fpQual && Token::Match(tok1->next(), "%name%")) {
3343+
// function pointer
3344+
TokenList::copyTokens(tok1->next(), fpArgList, usingEnd->previous());
3345+
Token* const copyEnd = TokenList::copyTokens(tok1, start, fpQual->link()->previous());
3346+
tok1->deleteThis();
3347+
Token* const rightPar = copyEnd->next()->insertToken(")");
3348+
Token::createMutualLinks(tok1->next(), rightPar);
3349+
substitute = true;
3350+
} else if (fpArgList && !fpQual && Token::Match(tok1->next(), "* const| %name%")) {
3351+
// function pointer
3352+
Token* const dest = tok1->tokAt(tok1->strAt(2) == "const" ? 3 : 2);
3353+
Token* const copyEndArgs = TokenList::copyTokens(dest, fpArgList, usingEnd->previous());
3354+
Token* const copyEndRet = TokenList::copyTokens(tok1, start, fpArgList->previous());
3355+
Token* const leftPar = copyEndRet->insertToken("(");
3356+
Token* const rightPar = copyEndArgs->link()->tokAt(-1)->insertToken(")");
3357+
Token::createMutualLinks(leftPar, rightPar);
3358+
tok1->deleteThis();
3359+
substitute = true;
33283360
} else {
33293361
// add some qualification back if needed
33303362
std::string removed1 = std::move(removed);
@@ -6931,8 +6963,7 @@ void Tokenizer::simplifyFunctionParameters()
69316963
}
69326964

69336965
// Find the function e.g. foo( x ) or foo( x, y )
6934-
else if (Token::Match(tok, "%name% ( %name% [,)]") &&
6935-
!(tok->strAt(-1) == ":" || tok->strAt(-1) == "," || tok->strAt(-1) == "::")) {
6966+
else if (Token::Match(tok, "%name% ( %name% [,)]") && !Token::Match(tok->tokAt(-1), ":|,|::|=")) {
69366967
// We have found old style function, now we need to change it
69376968

69386969
// First step: Get list of argument names in parentheses

test/testsimplifyusing.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class TestSimplifyUsing : public TestFixture {
7373
TEST_CASE(simplifyUsing34);
7474
TEST_CASE(simplifyUsing35);
7575
TEST_CASE(simplifyUsing36);
76+
TEST_CASE(simplifyUsing37);
7677

7778
TEST_CASE(simplifyUsing8970);
7879
TEST_CASE(simplifyUsing8971);
@@ -882,6 +883,23 @@ class TestSimplifyUsing : public TestFixture {
882883
ASSERT_EQUALS("", errout_str());
883884
}
884885

886+
void simplifyUsing37() {
887+
const char code1[] = "using fp1_t = int(*)(int);\n"
888+
"using fp2_t = int(* const)(int);\n"
889+
"fp1_t fp1;\n"
890+
"fp2_t fp2;\n";
891+
const char expected1[] = "int ( * fp1 ) ( int ) ; int ( * const fp2 ) ( int ) ;";
892+
ASSERT_EQUALS(expected1, tok(code1));
893+
ASSERT_EQUALS("", errout_str());
894+
895+
const char code2[] = "using f_t = int(int);\n"
896+
"f_t* fp1;\n"
897+
"f_t* const fp2;\n";
898+
const char expected2[] = "int ( * fp1 ) ( int ) ; int ( * const fp2 ) ( int ) ;";
899+
ASSERT_EQUALS(expected2, tok(code2));
900+
ASSERT_EQUALS("", errout_str());
901+
}
902+
885903
void simplifyUsing8970() {
886904
const char code[] = "using V = std::vector<int>;\n"
887905
"struct A {\n"

0 commit comments

Comments
 (0)