Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: do not allow struct{const;}



details:   https://anonhg.NetBSD.org/src/rev/3380ba1cb262
branches:  trunk
changeset: 984498:3380ba1cb262
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jul 10 11:22:19 2021 +0000

description:
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.

diffstat:

 tests/usr.bin/xlint/lint1/msg_249.c   |   4 ++--
 tests/usr.bin/xlint/lint1/msg_249.exp |   2 +-
 usr.bin/xlint/lint1/cgram.y           |  20 +++++---------------
 3 files changed, 8 insertions(+), 18 deletions(-)

diffs (68 lines):

diff -r 3bf60f89e721 -r 3380ba1cb262 tests/usr.bin/xlint/lint1/msg_249.c
--- a/tests/usr.bin/xlint/lint1/msg_249.c       Sat Jul 10 10:56:30 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_249.c       Sat Jul 10 11:22:19 2021 +0000
@@ -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 @@
        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;
 };
diff -r 3bf60f89e721 -r 3380ba1cb262 tests/usr.bin/xlint/lint1/msg_249.exp
--- a/tests/usr.bin/xlint/lint1/msg_249.exp     Sat Jul 10 10:56:30 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_249.exp     Sat Jul 10 11:22:19 2021 +0000
@@ -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]
diff -r 3bf60f89e721 -r 3380ba1cb262 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sat Jul 10 10:56:30 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sat Jul 10 11:22:19 2021 +0000
@@ -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 @@
                $$ = $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;



Home | Main Index | Thread Index | Old Index