Module Name: src
Committed By: rillig
Date: Wed Jun 28 21:41:27 UTC 2023
Modified Files:
src/tests/usr.bin/xlint/lint1: expr_sizeof.c
Log Message:
tests/lint: demonstrate wrong size calculation in anonymous union
To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/expr_sizeof.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/expr_sizeof.c
diff -u src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.5 src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.6
--- src/tests/usr.bin/xlint/lint1/expr_sizeof.c:1.5 Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/expr_sizeof.c Wed Jun 28 21:41:27 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: expr_sizeof.c,v 1.5 2023/03/28 14:44:34 rillig Exp $ */
+/* $NetBSD: expr_sizeof.c,v 1.6 2023/06/28 21:41:27 rillig Exp $ */
# 3 "expr_sizeof.c"
/*
@@ -73,3 +73,30 @@ variable_length_array(int n)
/* expect+1: error: negative array dimension (-4) [20] */
typedef int sizeof_local_arr[-(int)sizeof(local_arr)];
}
+
+/*
+ * Ensure that anonymous structs and unions are handled correctly. They were
+ * added in C11, and lint did not properly support them until 2023.
+ */
+void
+anonymous_struct_and_union(void)
+{
+ struct {
+ union {
+ unsigned char uc16[16];
+ unsigned char uc32[32];
+ };
+ } su_16_32;
+ /* FIXME: Must be 32, not 48. */
+ /* expect+1: error: negative array dimension (-48) [20] */
+ typedef int sizeof_su_16_32[-(int)sizeof(su_16_32)];
+
+ union {
+ struct {
+ unsigned char uc16[16];
+ unsigned char uc32[32];
+ };
+ } us_16_32;
+ /* expect+1: error: negative array dimension (-48) [20] */
+ typedef int sizeof_us_16_32[-(int)sizeof(us_16_32)];
+}