Module Name:    src
Committed By:   rillig
Date:           Tue Aug  3 20:57:06 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_union_cast.c d_c99_union_cast.exp
            msg_328.c msg_328.exp msg_329.c msg_329.exp
        src/usr.bin/xlint/lint1: err.c tree.c

Log Message:
lint: union casts are only available as a GCC extension, not in C99


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/d_c99_union_cast.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_328.c \
    src/tests/usr.bin/xlint/lint1/msg_328.exp \
    src/tests/usr.bin/xlint/lint1/msg_329.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_329.exp
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.328 -r1.329 src/usr.bin/xlint/lint1/tree.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/d_c99_union_cast.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_union_cast.c:1.6 src/tests/usr.bin/xlint/lint1/d_c99_union_cast.c:1.7
--- src/tests/usr.bin/xlint/lint1/d_c99_union_cast.c:1.6	Tue Aug  3 20:46:10 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_union_cast.c	Tue Aug  3 20:57:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_union_cast.c,v 1.6 2021/08/03 20:46:10 rillig Exp $	*/
+/*	$NetBSD: d_c99_union_cast.c,v 1.7 2021/08/03 20:57:06 rillig Exp $	*/
 # 3 "d_c99_union_cast.c"
 
 /* C99 does not define union cast, it is a GCC extension. */
@@ -18,9 +18,9 @@ union foo {
 void
 foo(struct bar *a)
 {
-	/* TODO: warn about union casts in general */
+	/* expect+1: error: union cast is a GCC extension [328] */
 	a = ((union foo)a).a;
-	/* expect+1: error: type 'pointer to char' is not a member of 'union foo' [329] */
+	/* expect+1: error: union cast is a GCC extension [328] */
 	a = ((union foo)"string");
 	a->a++;
 }

Index: src/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp:1.5 src/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp:1.6
--- src/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp:1.5	Tue Aug  3 20:46:10 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp	Tue Aug  3 20:57:06 2021
@@ -1 +1,2 @@
-d_c99_union_cast.c(24): error: type 'pointer to char' is not a member of 'union foo' [329]
+d_c99_union_cast.c(22): error: union cast is a GCC extension [328]
+d_c99_union_cast.c(24): error: union cast is a GCC extension [328]

Index: src/tests/usr.bin/xlint/lint1/msg_328.c
diff -u src/tests/usr.bin/xlint/lint1/msg_328.c:1.2 src/tests/usr.bin/xlint/lint1/msg_328.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_328.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_328.c	Tue Aug  3 20:57:06 2021
@@ -1,7 +1,19 @@
-/*	$NetBSD: msg_328.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_328.c,v 1.3 2021/08/03 20:57:06 rillig Exp $	*/
 # 3 "msg_328.c"
 
-// Test for message: union cast is a C9X feature [328]
+// Test for message: union cast is a GCC extension [328]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-flags: -Sw */
+
+union target {
+	int b;
+};
+
+void
+foo(void)
+{
+	union target arg = { 123 };
+	/* expect+1: error: union cast is a GCC extension [328] */
+	arg = (union target)3;
+	arg.b++;
+}
Index: src/tests/usr.bin/xlint/lint1/msg_328.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_328.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_328.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_328.exp:1.2	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_328.exp	Tue Aug  3 20:57:06 2021
@@ -1 +1 @@
-msg_328.c(6): error: syntax error ':' [249]
+msg_328.c(17): error: union cast is a GCC extension [328]
Index: src/tests/usr.bin/xlint/lint1/msg_329.c
diff -u src/tests/usr.bin/xlint/lint1/msg_329.c:1.2 src/tests/usr.bin/xlint/lint1/msg_329.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_329.c:1.2	Sun Jan 24 17:44:37 2021
+++ src/tests/usr.bin/xlint/lint1/msg_329.c	Tue Aug  3 20:57:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_329.c,v 1.2 2021/01/24 17:44:37 rillig Exp $	*/
+/*	$NetBSD: msg_329.c,v 1.3 2021/08/03 20:57:06 rillig Exp $	*/
 # 3 "msg_329.c"
 
 // Test for message: type '%s' is not a member of '%s' [329]
@@ -30,9 +30,6 @@ example(void)
 	 *
 	 * This is a GCC extension.
 	 * See https://gcc.gnu.org/onlinedocs/gcc/Cast-to-Union.html.
-	 *
-	 * FIXME: lint says in message 328 that "union cast is a C9X feature",
-	 *  but that is wrong.  It is a GCC feature.
 	 */
 	union u u_i1 = (union u)3;
 	union u u_vp = (union u)(void *)0;

Index: src/tests/usr.bin/xlint/lint1/msg_329.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_329.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_329.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_329.exp:1.3	Sun Mar 21 20:45:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_329.exp	Tue Aug  3 20:57:06 2021
@@ -1 +1 @@
-msg_329.c(39): error: type 'pointer to char' is not a member of 'union u' [329]
+msg_329.c(36): error: type 'pointer to char' is not a member of 'union u' [329]

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.133 src/usr.bin/xlint/lint1/err.c:1.134
--- src/usr.bin/xlint/lint1/err.c:1.133	Tue Aug  3 18:44:33 2021
+++ src/usr.bin/xlint/lint1/err.c	Tue Aug  3 20:57:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.133 2021/08/03 18:44:33 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.134 2021/08/03 20:57:06 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.133 2021/08/03 18:44:33 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.134 2021/08/03 20:57:06 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -382,7 +382,7 @@ const char *const msgs[] = {
 	"variable declaration in for loop",			      /* 325 */
 	"%s attribute ignored for %s",				      /* 326 */
 	"declarations after statements is a C99 feature",	      /* 327 */
-	"union cast is a C9X feature",				      /* 328 */
+	"union cast is a GCC extension",			      /* 328 */
 	"type '%s' is not a member of '%s'",			      /* 329 */
 	"operand of '%s' must be bool, not '%s'",		      /* 330 */
 	"left operand of '%s' must be bool, not '%s'",		      /* 331 */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.328 src/usr.bin/xlint/lint1/tree.c:1.329
--- src/usr.bin/xlint/lint1/tree.c:1.328	Tue Aug  3 18:38:02 2021
+++ src/usr.bin/xlint/lint1/tree.c	Tue Aug  3 20:57:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.328 2021/08/03 18:38:02 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.329 2021/08/03 20:57:06 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.328 2021/08/03 18:38:02 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.329 2021/08/03 20:57:06 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -3395,8 +3395,8 @@ cast(tnode_t *tn, type_t *tp)
 	} else if (nt == UNION) {
 		sym_t *m;
 		struct_or_union *str = tp->t_str;
-		if (!Sflag) {
-			/* union cast is a C9X feature */
+		if (!gflag) {
+			/* union cast is a GCC extension */
 			error(328);
 			return NULL;
 		}

Reply via email to