Opened 7 years ago

Closed 4 years ago

#9479 closed defect (fixed)

internalAstError on typedefed default arguments

Reported by: pfultz2 Owned by: noone
Priority: Normal Milestone: 2.9
Component: Other Version:
Keywords: ast syntaxError simplifyTypedef Cc:

Description

The code compiles with clang and gcc:

typedef int *a;
void b(a = a());

But fails on cppcheck with a syntax error:

Syntax Error: AST broken, binary operator '=' doesn't have two operands. [internalAstError]
void b(a = a());
         ^

Change History (6)

comment:1 by pfultz2, 7 years ago

Keywords: simplifyTypedef added

comment:2 by Daniel Marjamäki, 6 years ago

what does it do.. does it declare a nameless parameter that is initialized with a value? is it logically equivalent with void b(a)?

can we just remove the redundant initialization in the tokenizer?

comment:3 by pfultz2, 6 years ago

does it declare a nameless parameter that is initialized with a value?

Yes, its initialized to the default constructed value(ie a() or nullptr).

is it logically equivalent with void b(a)?

Not really. You can't call it without any arguments(ie b()).

can we just remove the redundant initialization in the tokenizer?

That might affect function matching. Maybe you could replace it with {}?

comment:4 by chrchr, 4 years ago

Related: #11232

comment:5 by Daniel Marjamäki, 4 years ago

Fixed by 5e0fc24bb7f078c2f5446a228d5dbe455223a107

The a() is simplified to (int *)0

comment:6 by Daniel Marjamäki, 4 years ago

Milestone: 2.9
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.