scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit eb450de6fc3e75a0a12059776e2d45db20be4075
parent 55cd0d69db26723f8863197fbfcd8d130c9605f3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  7 Jan 2025 21:45:14 +0100

cc1: Do not accept empty structs

This was a known bug but not fixed since many years ago.

Diffstat:
Msrc/cmd/scc-cc/cc1/decl.c | 3+--
Atests/cc/error/0039-struct.c | 22++++++++++++++++++++++
Mtests/cc/error/scc-tests.lst | 1+
Dtests/cc/execute/0102-bug.c | 14--------------
Mtests/cc/execute/scc-tests.lst | 1-
5 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/cmd/scc-cc/cc1/decl.c b/src/cmd/scc-cc/cc1/decl.c @@ -813,8 +813,7 @@ structdcl(void) error("too many levels of nested structure or union definitions"); ++nested; - while (yytoken != '}') - fieldlist(tp); + do fieldlist(tp); while (yytoken != '}'); --nested; deftype(tp); diff --git a/tests/cc/error/0039-struct.c b/tests/cc/error/0039-struct.c @@ -0,0 +1,22 @@ +/* +PATTERN: +0039-struct.c:11: warning: type defaults to 'int' in declaration +0039-struct.c:11: warning: empty declaration +0039-struct.c:11: error: expected ';' before '}' +0039-struct.c:19: warning: 'cap' defined but not used +0039-struct.c:19: warning: 'v' defined but not used +. +*/ + +typedef struct { } Vec; + +static void +vecresize(Vec *v, int cap) +{ + return; +} + +int main() +{ + return 0; +} diff --git a/tests/cc/error/scc-tests.lst b/tests/cc/error/scc-tests.lst @@ -36,3 +36,4 @@ 0036-func.c 0037-pointer.c 0038-void.c +0039-struct.c diff --git a/tests/cc/execute/0102-bug.c b/tests/cc/execute/0102-bug.c @@ -1,14 +0,0 @@ -// This wouldn't compile - -typedef struct { } Vec; - -static void -vecresize(Vec *v, int cap) -{ - return; -} - -int main() -{ - return 0; -} diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -92,7 +92,6 @@ 0097-extern.c 0098-tentative.c 0099-tentative.c -0102-bug.c 0103-voidparm.c 0104-qbebug.c 0105-shl.c