summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorrillig <rillig@NetBSD.org>2023-06-30 22:27:47 +0000
committerrillig <rillig@NetBSD.org>2023-06-30 22:27:47 +0000
commitf17c5ba8cce26bcd6614bcd52c8a632fc9bb88e6 (patch)
treea01c18cefef334773a63c7790b8dec576e4d7e4e /tests
parentebd8f80ef2f4a48804834ac957ff01b21345830f (diff)
tests/lint: test initializing an unnamed union
Diffstat (limited to 'tests')
-rw-r--r--tests/usr.bin/xlint/lint1/init_braces.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/usr.bin/xlint/lint1/init_braces.c b/tests/usr.bin/xlint/lint1/init_braces.c
index ceb2dad558a..84868b586be 100644
--- a/tests/usr.bin/xlint/lint1/init_braces.c
+++ b/tests/usr.bin/xlint/lint1/init_braces.c
@@ -1,4 +1,4 @@
-/* $NetBSD: init_braces.c,v 1.5 2023/06/30 21:06:18 rillig Exp $ */
+/* $NetBSD: init_braces.c,v 1.6 2023/06/30 22:27:47 rillig Exp $ */
# 3 "init_braces.c"
/*
@@ -96,3 +96,38 @@ init_anonymous_struct_and_union(void)
return var.times.t0.ns;
}
+
+// Minimized example taken from jemalloc.c, init_lock.
+unsigned char
+init_unnamed_union(void)
+{
+ struct init_unnamed_union {
+ union {
+ struct {
+ struct padded_union {
+ unsigned char pad1[3];
+ union {
+ unsigned char u1;
+ unsigned char u2;
+ };
+ unsigned char pad2[3];
+ } padded_union;
+ };
+ };
+ };
+
+ struct init_unnamed_union var = {
+ {
+ {
+ .padded_union = {
+ .pad1 = { 0, 0, 0 },
+/* FIXME: Allow access to unnamed struct/union members. */
+/* expect+1: error: type 'struct padded_union' does not have member 'u1' [101] */
+ .u1 = 0,
+ .pad2 = { 0, 0, 0 },
+ },
+ }
+ },
+ };
+ return var.padded_union.u1;
+}