ref: 7f6626e8c56822f2294ab095b4c23b8244539b6b
parent: 39efe97b2fff40d0e17fab3d0ddbc58778aca1eb
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Nov 15 16:03:04 EST 2021
cc1: Ensure namespace in array expressions When the size of an array is calculated we have to ensure that the namespace if changed to NS_IDEN, because the expression may use enumeration constants. If the array is declared inside of a struct the current namespace is the struct namespace and not NS_IDEN.
--- a/src/cmd/cc/cc1/decl.c
+++ b/src/cmd/cc/cc1/decl.c
@@ -117,7 +117,10 @@
{
Node *np = NULL;
TINT n = 0;
+ int ns;
+ ns = namespace;
+ namespace = NS_IDEN;
expect('[');
if (yytoken != ']') {
if ((np = constexpr()) == NULL) {
@@ -130,6 +133,7 @@
freetree(np);
}
}
+ namespace = ns;
expect(']');
push(dp, ARY, n);
@@ -773,9 +777,8 @@
error("too many levels of nested structure or union definitions");
++nested;
- while (yytoken != '}') {
+ while (yytoken != '}')
fieldlist(tp);
- }
--nested;
deftype(tp);