Tue Mar 30 15:10:46 2021 UTC ()
lint: reword message for very unlikely .member in array initialization


(rillig)
diff -r1.18 -r1.19 src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -r1.180 -r1.181 src/usr.bin/xlint/lint1/init.c

cvs diff -r1.18 -r1.19 src/tests/usr.bin/xlint/lint1/Attic/d_c99_init.exp (expand / switch to unified diff)

--- src/tests/usr.bin/xlint/lint1/Attic/d_c99_init.exp 2021/03/30 15:05:05 1.18
+++ src/tests/usr.bin/xlint/lint1/Attic/d_c99_init.exp 2021/03/30 15:10:46 1.19
@@ -1,18 +1,18 @@ @@ -1,18 +1,18 @@
1d_c99_init.c(23): error: too many initializers [174] 1d_c99_init.c(23): error: too many initializers [174]
2d_c99_init.c(63): error: cannot initialize 'pointer to const void' from 'struct any' [185] 2d_c99_init.c(63): error: cannot initialize 'pointer to const void' from 'struct any' [185]
3d_c99_init.c(80): error: too many array initializers, expected 3 [173] 3d_c99_init.c(80): error: too many array initializers, expected 3 [173]
4d_c99_init.c(139): error: too many struct/union initializers [172] 4d_c99_init.c(139): error: too many struct/union initializers [172]
5d_c99_init.c(145): error: syntax error 'named member must only be used with struct/union' [249] 5d_c99_init.c(145): error: syntax error 'designator '.member' is only for struct/union' [249]
6d_c99_init.c(232): error: too many struct/union initializers [172] 6d_c99_init.c(232): error: too many struct/union initializers [172]
7d_c99_init.c(238): warning: illegal combination of integer (char) and pointer (pointer to char) [183] 7d_c99_init.c(238): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
8d_c99_init.c(242): warning: illegal combination of integer (char) and pointer (pointer to char) [183] 8d_c99_init.c(242): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
9d_c99_init.c(281): error: cannot initialize 'struct <unnamed>' from 'int' [185] 9d_c99_init.c(281): error: cannot initialize 'struct <unnamed>' from 'int' [185]
10d_c99_init.c(323): error: duplicate case in switch: 0 [199] 10d_c99_init.c(323): error: duplicate case in switch: 0 [199]
11d_c99_init.c(332): error: undefined struct/union member: r [101] 11d_c99_init.c(332): error: undefined struct/union member: r [101]
12d_c99_init.c(339): error: undefined struct/union member: r [101] 12d_c99_init.c(339): error: undefined struct/union member: r [101]
13d_c99_init.c(346): error: undefined struct/union member: r [101] 13d_c99_init.c(346): error: undefined struct/union member: r [101]
14d_c99_init.c(355): error: undefined struct/union member: unknown_value [101] 14d_c99_init.c(355): error: undefined struct/union member: unknown_value [101]
15d_c99_init.c(361): error: undefined struct/union member: unknown_value [101] 15d_c99_init.c(361): error: undefined struct/union member: unknown_value [101]
16d_c99_init.c(365): error: syntax error 'designator '[...]' is only for arrays' [249] 16d_c99_init.c(365): error: syntax error 'designator '[...]' is only for arrays' [249]
17d_c99_init.c(366): error: undefined struct/union member: member [101] 17d_c99_init.c(366): error: undefined struct/union member: member [101]
18d_c99_init.c(372): warning: structure has no named members [65] 18d_c99_init.c(372): warning: structure has no named members [65]

cvs diff -r1.180 -r1.181 src/usr.bin/xlint/lint1/init.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/init.c 2021/03/30 15:07:53 1.180
+++ src/usr.bin/xlint/lint1/init.c 2021/03/30 15:10:46 1.181
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: init.c,v 1.180 2021/03/30 15:07:53 rillig Exp $ */ 1/* $NetBSD: init.c,v 1.181 2021/03/30 15:10:46 rillig Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1994, 1995 Jochen Pohl 4 * Copyright (c) 1994, 1995 Jochen Pohl
5 * Copyright (c) 2021 Roland Illig 5 * Copyright (c) 2021 Roland Illig
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) && !defined(lint) 40#if defined(__RCSID) && !defined(lint)
41__RCSID("$NetBSD: init.c,v 1.180 2021/03/30 15:07:53 rillig Exp $"); 41__RCSID("$NetBSD: init.c,v 1.181 2021/03/30 15:10:46 rillig Exp $");
42#endif 42#endif
43 43
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46 46
47#include "lint1.h" 47#include "lint1.h"
48 48
49 49
50/* 50/*
51 * Initialization of global or local objects, like in: 51 * Initialization of global or local objects, like in:
52 * 52 *
53 * int number = 12345; 53 * int number = 12345;
54 * int number_with_braces = { 12345 }; 54 * int number_with_braces = { 12345 };
@@ -442,30 +442,29 @@ designator_look_up(const struct designat @@ -442,30 +442,29 @@ designator_look_up(const struct designat
442{ 442{
443 switch (tp->t_tspec) { 443 switch (tp->t_tspec) {
444 case STRUCT: 444 case STRUCT:
445 case UNION: 445 case UNION:
446 if (dr->dr_name == NULL) { 446 if (dr->dr_name == NULL) {
447 /* syntax error '%s' */ 447 /* syntax error '%s' */
448 error(249, "designator '[...]' is only for arrays"); 448 error(249, "designator '[...]' is only for arrays");
449 return sym_type(first_named_member(tp)); 449 return sym_type(first_named_member(tp));
450 } 450 }
451 451
452 return look_up_member_type(tp, dr->dr_name); 452 return look_up_member_type(tp, dr->dr_name);
453 case ARRAY: 453 case ARRAY:
454 if (dr->dr_name != NULL) { 454 if (dr->dr_name != NULL) {
455 /* TODO: reword; kept for compatibility */ 
456 /* syntax error '%s' */ 455 /* syntax error '%s' */
457 error(249, 456 error(249,
458 "named member must only be used with struct/union"); 457 "designator '.member' is only for struct/union");
459 } 458 }
460 return tp->t_subt; 459 return tp->t_subt;
461 default: 460 default:
462 /* syntax error '%s' */ 461 /* syntax error '%s' */
463 error(249, "scalar type cannot use designator"); 462 error(249, "scalar type cannot use designator");
464 return tp; 463 return tp;
465 } 464 }
466} 465}
467 466
468 467
469#ifdef DEBUG 468#ifdef DEBUG
470static void 469static void
471designation_debug(const struct designation *dn) 470designation_debug(const struct designation *dn)