commit 5a6e26e28744a0fa4efe9f6e032bd40c647b3749
parent a7a08bb3d51b852995346c96d94265ea936731e5
Author: Zhaoming Luo <zhml@posteo.com>
Date: Wed, 3 Jun 2026 04:39:45 +0000
cc1: Try parsing specifiers after struct/union/enum
In specifier(), the type is returned after parsing the
struct/union/enum specifier. Therefore, the compile will fail with
the declaration like: `struct S const s;`.
However, according to the syntax of `declaration-specifiers` in c99
spec 6.7, it's accpectable to have other specifiers or qualifiers
following the struct/union/enum specifier, which is a type specifier.
To follow the c99 spec, continue looking for other specifiers or
qualifiers after a struct/union/enum specifier rather than return
immediately.
Diffstat:
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/cmd/scc-cc/cc1/decl.c b/src/cmd/scc-cc/cc1/decl.c
@@ -755,7 +755,6 @@ specifier(int *sclass, int *qualifier)
if (size || sign)
errorp("invalid type specification");
tp = (*dcl)();
- goto return_type;
} else {
next();
}
diff --git a/tests/cc/execute/0275-struct.c b/tests/cc/execute/0275-struct.c
@@ -0,0 +1,12 @@
+struct S { int a; int b; };
+struct S const s = {1, 2};
+
+int
+main()
+{
+ if(s.a != 1)
+ return 1;
+ if(s.b != 2)
+ return 2;
+ return 0;
+}
diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst
@@ -265,3 +265,4 @@
0272-div
0273-cpp
0274-loop
+0275-struct