shithub: scc

Download patch

ref: a8cd756a8912fe2a544d67110ecbdb28a343bc95
parent: 079f3c6e917203d8d5a2043182927231c60ea231
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat May 28 08:29:09 EDT 2022

cc1: Accept empty parameters in macros

A macro accepting a parameter can be instantiated without
anything between the parenthesis, because in that case it
receives an empty parameter. We have to differentiate that
case from the case that acutally has no parameter.

As this patch modifies the behaviour and ahead() is not called
always befor calling parameter() we have to explicit trim
spaces at the beginning of the parameters.

--- a/src/cmd/cc/cc1/cpp.c
+++ b/src/cmd/cc/cc1/cpp.c
@@ -128,6 +128,8 @@
 			end = input->begin - 1;
 			while (end > begin && isspace(end[-1]))
 				--end;
+			while (begin < end && isspace(begin[0]))
+				++begin;
 
 			siz = end - begin;
 			s = memcpy(xmalloc(siz+1), begin, siz);
@@ -153,7 +155,8 @@
 	disexpand = 1;
 	next();
 	n = 0;
-	if (ahead() == ')') {
+
+	if (mp->npars == 0 && ahead() == ')') {
 		next();
 	} else {
 		do {
@@ -161,6 +164,7 @@
 			mp->arglist[n] = parameter(mp);
 		} while (++n < NR_MACROARG && yytoken == ',');
 	}
+
 	if (yytoken != ')')
 		error("incorrect macro function-alike invocation");
 	disexpand = 0;