scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 079e6ba6e4a218a64d593894050f546ca5cd3d34
parent 52ef3bfb727b3f197caf482fbd151a062fa34c70
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 15 Jun 2022 21:48:25 +0200

cc1: Improve errors in typedef'ed function types

If a typedef function type is used to define a function we should
give a clear error messae and try to don't break any assumption
that the code does.

Diffstat:
Msrc/cmd/cc/cc1/decl.c | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/cmd/cc/cc1/decl.c b/src/cmd/cc/cc1/decl.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <stdarg.h> #include <stdlib.h> #include <string.h> @@ -505,8 +506,16 @@ funbody(Symbol *sym, Symbol *pars[]) case TYPE: case SCLASS: case TYPEIDEN: + if (curctx < PARAMCTX) { + assert(!pars); + errorp("typedef'ed function type cannot be instantiated"); + curctx = PARAMCTX; + pars = (Symbol *[]) {NULL}; + } + if (curctx != PARAMCTX) errorp("nested function declaration"); + if (sym && sym->ns == NS_IDEN) break; default: