~mcf/cproc

8755378092c00fbae007abbd3f5cb83df0f50ac2 — Michael Forney 3 months ago 70a5325
decl: Don't accept abstract function declarator when disallowed

When declarator() is called with allowabstract == false, the caller
can assume that it will always return the identifier being declared.
However, abstract function declarators were incorrectly accepted
in this case with name set to NULL instead of erroring out due to
invalid syntax.

To fix this, only skip forward to function declarator parsing for
abstract declarators, since this is the only case where we can't
immediately tell whether we have a parenthesized declarator or a
function declarator.

Fixes #74.
1 files changed, 11 insertions(+), 9 deletions(-)

M decl.c
M decl.c => decl.c +11 -9
@@ 480,16 480,18 @@ declaratortypes(struct scope *s, struct list *result, char **name, bool allowabs
	switch (tok.kind) {
	case TLPAREN:
		next();
		switch (tok.kind) {
		case TMUL:
		case TLPAREN:
			break;
		case TIDENT:
			if (!allowabstract || !istypename(s, tok.lit))
		if (allowabstract) {
			switch (tok.kind) {
			case TMUL:
			case TLPAREN:
				break;
			/* fallthrough */
		default:
			goto func;
			case TIDENT:
				if (!istypename(s, tok.lit))
					break;
				/* fallthrough */
			default:
				goto func;
			}
		}
		declaratortypes(s, result, name, allowabstract);
		expect(TRPAREN, "after parenthesized declarator");