From 8258d5b63292c20650935b79056de9e017f983e4 Mon Sep 17 00:00:00 2001 From: chrchr-github Date: Sat, 5 Oct 2024 11:39:21 +0200 Subject: [PATCH] Fix #13182 FP AssignmentIntegerToAddress with functional-style cast --- lib/tokenize.cpp | 4 ++++ test/testsimplifytypedef.cpp | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9102c750600..cb25df999fd 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -786,6 +786,10 @@ namespace { tok2 = insertTokens(tok2, mRangeTypeQualifiers); Token* tok3 = tok2->insertToken(")"); Token::createMutualLinks(tok, tok3); + tok->insertTokenBefore("("); + tok3 = tok3->linkAt(1); + tok3 = tok3->insertToken(")"); + Token::createMutualLinks(tok->tokAt(-1), tok3); } return; } diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index d0c7a21d336..7938260e183 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -3387,7 +3387,7 @@ class TestSimplifyTypedef : public TestFixture { // #11430 const char code3[] = "typedef char* T;\n" "T f() { return T(\"abc\"); }\n"; - ASSERT_EQUALS("char * f ( ) { return ( char * ) ( \"abc\" ) ; }", tok(code3)); + ASSERT_EQUALS("char * f ( ) { return ( ( char * ) ( \"abc\" ) ) ; }", tok(code3)); const char code4[] = "typedef struct _a *A;\n" // #13104 "typedef struct _b* B;\n" @@ -3399,6 +3399,17 @@ class TestSimplifyTypedef : public TestFixture { ASSERT_EQUALS("extern struct _a * ( * get ) ( struct _b * ) ; " "struct _a * f ( ) { return get ( 0 ) ; }", tok(code4)); + + const char code5[] = "struct S { int x; };\n" // #13182 + "typedef S* PS;\n" + "void f(void* a[], int i) {\n" + " PS(a[i])->x = i;\n" + "}\n"; + ASSERT_EQUALS("struct S { int x ; } ; " + "void f ( void * a [ ] , int i ) { " + "( ( S * ) ( a [ i ] ) ) . x = i ; " + "}", + tok(code5)); } void simplifyTypedef143() { // #11506