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.
This commit is contained in:
rillig 2021-12-21 21:42:21 +00:00
parent 6f6cd601b1
commit 6bf50d6b33
3 changed files with 38 additions and 11 deletions

View File

@ -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] */
};

View File

@ -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]

View File

@ -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);
}