Module Name: src
Committed By: rillig
Date: Tue Aug 3 21:18:24 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: gcc_cast_union.c gcc_cast_union.exp
src/usr.bin/xlint/lint1: decl.c
Log Message:
lint: in strict enum mode, error out on enum type mismatch in union cast
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/gcc_cast_union.c \
src/tests/usr.bin/xlint/lint1/gcc_cast_union.exp
cvs rdiff -u -r1.218 -r1.219 src/usr.bin/xlint/lint1/decl.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/gcc_cast_union.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_cast_union.c:1.2 src/tests/usr.bin/xlint/lint1/gcc_cast_union.c:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_cast_union.c:1.2 Tue Aug 3 21:09:26 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_cast_union.c Tue Aug 3 21:18:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gcc_cast_union.c,v 1.2 2021/08/03 21:09:26 rillig Exp $ */
+/* $NetBSD: gcc_cast_union.c,v 1.3 2021/08/03 21:18:24 rillig Exp $ */
# 3 "gcc_cast_union.c"
/*
@@ -81,7 +81,7 @@ test(void)
any = (union anything)E1;
any = (union anything)E2;
/* GCC allows enum mismatch even with -Wenum-conversion */
- /* XXX: Lint should warn about enum type mismatch */
+ /* expect+1: error: type 'enum other_enum' is not a member of 'union anything' [329] */
any = (union anything)OTHER;
/* expect+1: error: type 'pointer to char' is not a member of 'union anything' [329] */
any = (union anything)"char *";
Index: src/tests/usr.bin/xlint/lint1/gcc_cast_union.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_cast_union.exp:1.2 src/tests/usr.bin/xlint/lint1/gcc_cast_union.exp:1.3
--- src/tests/usr.bin/xlint/lint1/gcc_cast_union.exp:1.2 Tue Aug 3 21:09:26 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_cast_union.exp Tue Aug 3 21:18:24 2021
@@ -1,3 +1,4 @@
+gcc_cast_union.c(85): error: type 'enum other_enum' is not a member of 'union anything' [329]
gcc_cast_union.c(87): error: type 'pointer to char' is not a member of 'union anything' [329]
gcc_cast_union.c(90): error: type 'pointer to double' is not a member of 'union anything' [329]
gcc_cast_union.c(92): error: type 'pointer to double' is not a member of 'union anything' [329]
Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.218 src/usr.bin/xlint/lint1/decl.c:1.219
--- src/usr.bin/xlint/lint1/decl.c:1.218 Tue Aug 3 18:38:02 2021
+++ src/usr.bin/xlint/lint1/decl.c Tue Aug 3 21:18:24 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.218 2021/08/03 18:38:02 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.219 2021/08/03 21:18:24 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.218 2021/08/03 18:38:02 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.219 2021/08/03 21:18:24 rillig Exp $");
#endif
#include <sys/param.h>
@@ -2225,6 +2225,9 @@ eqtype(const type_t *tp1, const type_t *
if (t == STRUCT || t == UNION)
return tp1->t_str == tp2->t_str;
+ if (t == ENUM && eflag)
+ return tp1->t_enum == tp2->t_enum;
+
if (t == ARRAY && tp1->t_dim != tp2->t_dim) {
if (tp1->t_dim != 0 && tp2->t_dim != 0)
return false;