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: union casts are only available as ...



details:   https://anonhg.NetBSD.org/src/rev/778649540296
branches:  trunk
changeset: 985005:778649540296
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Aug 03 20:57:06 2021 +0000

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

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_union_cast.c   |   6 +++---
 tests/usr.bin/xlint/lint1/d_c99_union_cast.exp |   3 ++-
 tests/usr.bin/xlint/lint1/msg_328.c            |  20 ++++++++++++++++----
 tests/usr.bin/xlint/lint1/msg_328.exp          |   2 +-
 tests/usr.bin/xlint/lint1/msg_329.c            |   5 +----
 tests/usr.bin/xlint/lint1/msg_329.exp          |   2 +-
 usr.bin/xlint/lint1/err.c                      |   6 +++---
 usr.bin/xlint/lint1/tree.c                     |   8 ++++----
 8 files changed, 31 insertions(+), 21 deletions(-)

diffs (142 lines):

diff -r 3c6eb8e48331 -r 778649540296 tests/usr.bin/xlint/lint1/d_c99_union_cast.c
--- a/tests/usr.bin/xlint/lint1/d_c99_union_cast.c      Tue Aug 03 20:46:10 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_union_cast.c      Tue Aug 03 20:57:06 2021 +0000
@@ -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 @@
 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++;
 }
diff -r 3c6eb8e48331 -r 778649540296 tests/usr.bin/xlint/lint1/d_c99_union_cast.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp    Tue Aug 03 20:46:10 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_union_cast.exp    Tue Aug 03 20:57:06 2021 +0000
@@ -1,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]
diff -r 3c6eb8e48331 -r 778649540296 tests/usr.bin/xlint/lint1/msg_328.c
--- a/tests/usr.bin/xlint/lint1/msg_328.c       Tue Aug 03 20:46:10 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_328.c       Tue Aug 03 20:57:06 2021 +0000
@@ -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]
+
+/* lint1-flags: -Sw */
+
+union target {
+       int b;
+};
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void
+foo(void)
+{
+       union target arg = { 123 };
+       /* expect+1: error: union cast is a GCC extension [328] */
+       arg = (union target)3;
+       arg.b++;
+}
diff -r 3c6eb8e48331 -r 778649540296 tests/usr.bin/xlint/lint1/msg_328.exp
--- a/tests/usr.bin/xlint/lint1/msg_328.exp     Tue Aug 03 20:46:10 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_328.exp     Tue Aug 03 20:57:06 2021 +0000
@@ -1,1 +1,1 @@
-msg_328.c(6): error: syntax error ':' [249]
+msg_328.c(17): error: union cast is a GCC extension [328]
diff -r 3c6eb8e48331 -r 778649540296 tests/usr.bin/xlint/lint1/msg_329.c
--- a/tests/usr.bin/xlint/lint1/msg_329.c       Tue Aug 03 20:46:10 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_329.c       Tue Aug 03 20:57:06 2021 +0000
@@ -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 @@
         *
         * 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;
diff -r 3c6eb8e48331 -r 778649540296 tests/usr.bin/xlint/lint1/msg_329.exp
--- a/tests/usr.bin/xlint/lint1/msg_329.exp     Tue Aug 03 20:46:10 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_329.exp     Tue Aug 03 20:57:06 2021 +0000
@@ -1,1 +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]
diff -r 3c6eb8e48331 -r 778649540296 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Tue Aug 03 20:46:10 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Tue Aug 03 20:57:06 2021 +0000
@@ -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 @@
        "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 */
diff -r 3c6eb8e48331 -r 778649540296 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Tue Aug 03 20:46:10 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Tue Aug 03 20:57:06 2021 +0000
@@ -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 @@
        } 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;
                }



Home | Main Index | Thread Index | Old Index