Skip to content

Commit 5e0fc24

Browse files
committed
Fixed #11232 (Syntax Error: AST broken, binary operator '!=' doesn't have two operands)
1 parent f0ac0d8 commit 5e0fc24

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

lib/tokenize.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,10 +1390,19 @@ void Tokenizer::simplifyTypedef()
13901390
if (sameStartEnd)
13911391
typeEnd = typeStart;
13921392

1393+
// Is this a "T()" expression where T is a pointer type?
1394+
const bool isPointerTypeCall = !inOperator && Token::Match(tok2, "%name% ( )") && !pointers.empty();
1395+
13931396
// start substituting at the typedef name by replacing it with the type
13941397
Token* replStart = tok2; // track first replaced token
13951398
for (Token* tok3 = typeStart; tok3->str() != ";"; tok3 = tok3->next())
13961399
tok3->isSimplifiedTypedef(true);
1400+
if (isPointerTypeCall) {
1401+
tok2->deleteThis();
1402+
tok2->insertToken("0");
1403+
tok2 = tok2->next();
1404+
tok2->next()->insertToken("0");
1405+
}
13971406
tok2->str(typeStart->str());
13981407

13991408
// restore qualification if it was removed

test/testsimplifytypedef.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class TestSimplifyTypedef : public TestFixture {
188188
TEST_CASE(simplifyTypedef139);
189189
TEST_CASE(simplifyTypedef140); // #10798
190190
TEST_CASE(simplifyTypedef141); // #10144
191+
TEST_CASE(simplifyTypedef142); // T() when T is a pointer type
191192

192193
TEST_CASE(simplifyTypedefFunction1);
193194
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@@ -3051,6 +3052,18 @@ class TestSimplifyTypedef : public TestFixture {
30513052
ASSERT_EQUALS("class C { struct I { } ; } ;", tok(code));
30523053
}
30533054

3055+
void simplifyTypedef142() { // T() when T is a pointer type
3056+
// #11232
3057+
const char code1[] = "typedef int* T;\n"
3058+
"a = T();\n";
3059+
ASSERT_EQUALS("a = ( int * ) 0 ;", tok(code1));
3060+
3061+
// #9479
3062+
const char code2[] = "typedef int* T;\n"
3063+
"void f(T = T()){}\n";
3064+
ASSERT_EQUALS("void f ( int * = ( int * ) 0 ) { }", tok(code2));
3065+
}
3066+
30543067
void simplifyTypedefFunction1() {
30553068
{
30563069
const char code[] = "typedef void (*my_func)();\n"

0 commit comments

Comments
 (0)