shithub: scc

Download patch

ref: 079e6ba6e4a218a64d593894050f546ca5cd3d34
parent: 52ef3bfb727b3f197caf482fbd151a062fa34c70
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Jun 15 17:48:25 EDT 2022

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.

--- 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 @@
 	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: