Module Name: src
Committed By: rillig
Date: Tue Dec 21 21:42:21 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: init.c init.exp
src/usr.bin/xlint/lint1: init.c
Log Message:
lint: treat incomplete union in the same way as incomplete struct
The newly added tests triggered the assertion in begin_designation since
for incomplete types the initialization is stopped before handling the
first brace.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/init.c \
src/tests/usr.bin/xlint/lint1/init.exp
cvs rdiff -u -r1.226 -r1.227 src/usr.bin/xlint/lint1/init.c
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/init.c
diff -u src/tests/usr.bin/xlint/lint1/init.c:1.8 src/tests/usr.bin/xlint/lint1/init.c:1.9
--- src/tests/usr.bin/xlint/lint1/init.c:1.8 Tue Dec 21 21:16:08 2021
+++ src/tests/usr.bin/xlint/lint1/init.c Tue Dec 21 21:42:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.8 2021/12/21 21:16:08 rillig Exp $ */
+/* $NetBSD: init.c,v 1.9 2021/12/21 21:42:21 rillig Exp $ */
# 3 "init.c"
/*
@@ -73,14 +73,32 @@ struct {
do_nothing,
};
+
+/* expect+1: error: initialization of incomplete type 'incomplete struct incomplete_struct' [175] */
+struct incomplete_struct s1 = {
+ 1,
+/* expect+1: error: 's1' has incomplete type 'incomplete struct incomplete_struct' [31] */
+};
+
+/* expect+1: error: initialization of incomplete type 'incomplete struct incomplete_struct' [175] */
+struct incomplete_struct s2 = {
+ .member = 1,
+/* expect+1: error: 's2' has incomplete type 'incomplete struct incomplete_struct' [31] */
+};
+
+struct incomplete_struct {
+ int num;
+};
+
+
+/* expect+1: error: initialization of incomplete type 'incomplete union incomplete_union' [175] */
union incomplete_union u1 = {
- /* expect+1: error: too many struct/union initializers [172] */
1,
/* expect+1: error: 'u1' has incomplete type 'incomplete union incomplete_union' [31] */
};
+/* expect+1: error: initialization of incomplete type 'incomplete union incomplete_union' [175] */
union incomplete_union u2 = {
- /* expect+1: error: type 'incomplete union incomplete_union' does not have member 'member' [101] */
.member = 1,
/* expect+1: error: 'u2' has incomplete type 'incomplete union incomplete_union' [31] */
};
Index: src/tests/usr.bin/xlint/lint1/init.exp
diff -u src/tests/usr.bin/xlint/lint1/init.exp:1.8 src/tests/usr.bin/xlint/lint1/init.exp:1.9
--- src/tests/usr.bin/xlint/lint1/init.exp:1.8 Tue Dec 21 21:16:08 2021
+++ src/tests/usr.bin/xlint/lint1/init.exp Tue Dec 21 21:42:21 2021
@@ -1,5 +1,9 @@
init.c(16): error: empty array declaration: empty_array_with_initializer [190]
-init.c(78): error: too many struct/union initializers [172]
-init.c(80): error: 'u1' has incomplete type 'incomplete union incomplete_union' [31]
-init.c(84): error: type 'incomplete union incomplete_union' does not have member 'member' [101]
-init.c(86): error: 'u2' has incomplete type 'incomplete union incomplete_union' [31]
+init.c(78): error: initialization of incomplete type 'incomplete struct incomplete_struct' [175]
+init.c(81): error: 's1' has incomplete type 'incomplete struct incomplete_struct' [31]
+init.c(84): error: initialization of incomplete type 'incomplete struct incomplete_struct' [175]
+init.c(87): error: 's2' has incomplete type 'incomplete struct incomplete_struct' [31]
+init.c(95): error: initialization of incomplete type 'incomplete union incomplete_union' [175]
+init.c(98): error: 'u1' has incomplete type 'incomplete union incomplete_union' [31]
+init.c(101): error: initialization of incomplete type 'incomplete union incomplete_union' [175]
+init.c(104): error: 'u2' has incomplete type 'incomplete union incomplete_union' [31]
Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.226 src/usr.bin/xlint/lint1/init.c:1.227
--- src/usr.bin/xlint/lint1/init.c:1.226 Tue Dec 21 21:04:08 2021
+++ src/usr.bin/xlint/lint1/init.c Tue Dec 21 21:42:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.226 2021/12/21 21:04:08 rillig Exp $ */
+/* $NetBSD: init.c,v 1.227 2021/12/21 21:42:21 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.226 2021/12/21 21:04:08 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.227 2021/12/21 21:42:21 rillig Exp $");
#endif
#include <stdlib.h>
@@ -731,7 +731,7 @@ initialization_lbrace(initialization *in
warning(238);
}
- if (tp->t_tspec == STRUCT && tp->t_str->sou_incomplete) {
+ if (is_struct_or_union(tp->t_tspec) && tp->t_str->sou_incomplete) {
/* initialization of incomplete type '%s' */
error(175, type_name(tp));
in->in_err = true;
@@ -990,9 +990,14 @@ end_initialization(void)
void
begin_designation(void)
{
+ initialization *in;
brace_level *bl;
- bl = current_init()->in_brace_level;
+ in = current_init();
+ if (in->in_err)
+ return;
+
+ bl = in->in_brace_level;
lint_assert(bl != NULL);
designation_reset(&bl->bl_designation);
}