Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to parse function return function pointers #64

Open
minux opened this issue May 8, 2015 · 4 comments
Open

failed to parse function return function pointers #64

minux opened this issue May 8, 2015 · 4 comments

Comments

@minux
Copy link

minux commented May 8, 2015

void (*f(int *p))(void) {
    return (void *)0;
}
$ 8cc -c t2.c 
[ERROR] 8cc.h:426: t.c:1:25: ';' or ',' are expected, but got {
@andrewchambers
Copy link
Contributor

Looks like is_funcdef() in parse.c makes some incorrect assumptions so it tries to parse this as a decl.

@rui314
Copy link
Owner

rui314 commented May 8, 2015

That's right. is_funcdef returns a wrong result for the input. Maybe we should stop making a guess before calling the parser but instead call the parser directly, because making a good guess is as hard as parsing input.

@andrewchambers
Copy link
Contributor

The look ahead is good for readability. If we don't have the ability to save and reset the parser at choice points on an error, decl and function parsing may need to be combined into an ugly mess.

@andrewchambers
Copy link
Contributor

It actually might not be too bad, I think it comes down to a check in read_decl like:

decl = read_decl()
if ( peek == '{' && ! first decl in list  ) 
  error("function cannot appear in decl list");
if (peek == '{') { 
  if (sclass == typdef)
    error()
  parse_body() 
} 

Edit:
Yeah, this is what I am currently doing (my function is too big), but I don't handle old style arguments.
https://github.com/andrewchambers/cc/blob/master/parse/parse.go#L547

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants