Fix #11689 FP constStatement with nested typedefs (#5090)

* Fix #11689 FP constStatement with nested typedefs

* Add test
This commit is contained in:
chrchr-github 2023-05-26 06:12:40 +02:00 committed by GitHub
parent 107eea236f
commit beea1a2345
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -858,6 +858,8 @@ namespace {
// Function return type => replace array with "*"
for (const Token* a = mRangeAfterVar.first; Token::simpleMatch(a, "["); a = a->link()->next())
tok3->insertToken("*");
} else if (Token::Match(after->previous(), "%name% ( * %name% ) [")) {
after = after->linkAt(4)->next();
} else {
Token* prev = after->previous();
if (prev->isName() && prev != tok3)

View File

@ -68,6 +68,7 @@ private:
TEST_CASE(cfp7);
TEST_CASE(carray1);
TEST_CASE(carray2);
TEST_CASE(carray3);
TEST_CASE(cdonotreplace1);
TEST_CASE(cppfp1);
TEST_CASE(Generic1);
@ -458,6 +459,20 @@ private:
ASSERT_EQUALS("double x [ 10 ] [ 4 ] ;", simplifyTypedef(code));
}
void carray3() {
const char* code{};
code = "typedef int a[256];\n" // #11689
"typedef a b[256];\n"
"b* p;\n";
ASSERT_EQUALS("int ( * p ) [ 256 ] [ 256 ] ;", simplifyTypedef(code));
code = "typedef int a[1];\n"
"typedef a b[2];\n"
"typedef b c[3];\n"
"c* p;\n";
ASSERT_EQUALS("int ( * p ) [ 3 ] [ 2 ] [ 1 ] ;", simplifyTypedef(code));
}
void cdonotreplace1() {
const char code[] = "typedef int t;\n"
"int* t;";