Module Name:    src
Committed By:   rillig
Date:           Sat Jul 10 11:22:19 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_249.c msg_249.exp
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
lint: do not allow struct{const;}

In traditional C, a struct member was defined syntactically as
'type-specifier struct-declarator-list', the concept of a type-qualifier
was not known back then.

C90 invented the type-qualifier 'const' and relaxed the syntactic
requirement for struct member declarations by allowing 'const x'. Having
only a type-qualifier without an actual type may be regarded as an
"incomplete type", which would be forbidden by C90 and later.

Anyway, this doesn't occur in practice anyway, so there is no need for
lint to try to parse it.  This removes a bit of dead code, since a
type-qualifier-list can never have type struct or union.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_249.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_249.exp
cvs rdiff -u -r1.287 -r1.288 src/usr.bin/xlint/lint1/cgram.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_249.c
diff -u src/tests/usr.bin/xlint/lint1/msg_249.c:1.6 src/tests/usr.bin/xlint/lint1/msg_249.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_249.c:1.6	Sat Jul 10 10:30:26 2021
+++ src/tests/usr.bin/xlint/lint1/msg_249.c	Sat Jul 10 11:22:19 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_249.c,v 1.6 2021/07/10 10:30:26 rillig Exp $	*/
+/*	$NetBSD: msg_249.c,v 1.7 2021/07/10 11:22:19 rillig Exp $	*/
 # 3 "msg_249.c"
 
 // Test for message: syntax error '%s' [249]
@@ -54,6 +54,6 @@ struct cover_member_declaration {
 	const int noclass_declspecs;
 
 	/* cover 'noclass_declmods deftyp ...' */
-	/* expect+1: error: syntax error 'unnamed member' [249] */
+	/* expect+1: error: syntax error 'member without type' [249] */
 	const;
 };

Index: src/tests/usr.bin/xlint/lint1/msg_249.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_249.exp:1.5 src/tests/usr.bin/xlint/lint1/msg_249.exp:1.6
--- src/tests/usr.bin/xlint/lint1/msg_249.exp:1.5	Sat Jul 10 10:30:26 2021
+++ src/tests/usr.bin/xlint/lint1/msg_249.exp	Sat Jul 10 11:22:19 2021
@@ -1,4 +1,4 @@
 msg_249.c(10): error: syntax error '"' [249]
 msg_249.c(19): error: syntax error '"' [249]
 msg_249.c(33): error: syntax error ')' [249]
-msg_249.c(58): error: syntax error 'unnamed member' [249]
+msg_249.c(58): error: syntax error 'member without type' [249]

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.287 src/usr.bin/xlint/lint1/cgram.y:1.288
--- src/usr.bin/xlint/lint1/cgram.y:1.287	Sat Jul 10 10:56:30 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Jul 10 11:22:19 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.287 2021/07/10 10:56:30 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.288 2021/07/10 11:22:19 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.287 2021/07/10 10:56:30 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.288 2021/07/10 11:22:19 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -689,19 +689,9 @@ member_declaration:
 		$$ = $4;
 	  }
 	| clrtyp add_type_qualifier_list deftyp type_attribute_opt {
-		symtyp = FVFT;
-		if (!Sflag)
-			/* anonymous struct/union members is a C9X feature */
-			warning(49);
-		if (is_struct_or_union(dcs->d_type->t_tspec)) {
-			$$ = dcs->d_type->t_str->sou_first_member;
-			/* add all the members of the anonymous struct/union */
-			anonymize($$);
-		} else {
-			/* syntax error '%s' */
-			error(249, "unnamed member");
-			$$ = NULL;
-		}
+		/* syntax error '%s' */
+		error(249, "member without type");
+		$$ = NULL;
 	  }
 	| noclass_declspecs deftyp type_attribute_opt {
 		symtyp = FVFT;

Reply via email to