[cfe-dev] FunctionDecls by typedef crash the C++ front-end

Neil Booth neil at daikokuya.co.uk
Fri Oct 24 01:25:35 PDT 2008

Chris Lattner wrote:-

> On Oct 23, 2008, at 6:37 PM, Argiris Kirtzidis wrote:
> > e.g:
> >
> > typedef void fn(int);
> > fn f;
> >
> > There are no ParmVarDecls created for the 'f' FunctionDecl, and I  
> > assume
> > this is intended to save space.
> > This crashes the C++ front-end when trying to use the ParmVarDecls
> > (mostly for handling default args).
> >
> > In C there is no problem since ParmVarDecls are used only for
> > definitions, otherwise FunctionTypeProto is used
> Two options here.  The best is probably for the C++ front-end to  
> create the parm var decls in this case, to be consistent with "void  
> f(int);".  The typedef shouldn't affect the AST generated other than  
> the pretty type.
> Long term, I'd love to get rid of parm var decls in the common case.   
> They are needed for stuff like this in C:
> void f(int i, int x[i*42]);
> etc.  However, this is obviously not the common case, and most clients  
> don't care about parmvardecls in function prototypes.  Considering  
> that tons of headers have lots of function prototypes, I think this  
> would be a big win.  This isn't a particularly high priority though,

It depends how much info you wish to store.  The C standard says the
above is equivalent to

	void f(int, int [*]);

so you could store it as that if you're willing to lose the i and the x.


More information about the cfe-dev mailing list