shithub: scc

Download patch

ref: 71e7972a9bb2ccabbc85d51b0082e0110fd07b42
parent: 7526472b647e3559938eebc1c8aea98aa4f6ebed
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 11 14:05:00 EST 2021

cc1: Fix namespace for enumerations

The namespace must be modified before any token operation
is performed, otherwise we pollute the wrong namespace and
we insert the enum constants in other namespaces.

--- a/src/cmd/cc/cc1/decl.c
+++ b/src/cmd/cc/cc1/decl.c
@@ -796,12 +796,12 @@
 	tagsym = newtag();
 	tp = tagsym->type;
 
+	namespace = NS_IDEN;
 	if (!accept('{'))
 		goto restore_name;
 	if (tp->prop & TDEFINED)
 		errorp("redefinition of enumeration '%s'", tagsym->name);
 	deftype(tp);
-	namespace = NS_IDEN;
 
 	/* TODO: check incorrect values in val */
 	for (nctes = val = 0; yytoken != '}'; ++nctes, ++val) {