Module Name: src
Committed By: rillig
Date: Mon Dec 28 10:22:21 UTC 2020
Modified Files:
src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh
Added Files:
src/tests/usr.bin/xlint/lint1: d_struct_init_nested.c
Log Message:
lint1: add test for initializing nested structs
Discovered in var.c 1.774 from 2020-12-28.
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/t_integration.sh
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/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.17 src/tests/usr.bin/xlint/lint1/Makefile:1.18
--- src/tests/usr.bin/xlint/lint1/Makefile:1.17 Mon Dec 28 09:58:56 2020
+++ src/tests/usr.bin/xlint/lint1/Makefile Mon Dec 28 10:22:21 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.17 2020/12/28 09:58:56 rillig Exp $
+# $NetBSD: Makefile,v 1.18 2020/12/28 10:22:21 rillig Exp $
NOMAN= # defined
@@ -60,6 +60,7 @@ FILES+= d_nested_structs.c
FILES+= d_nolimit_init.c
FILES+= d_packed_structs.c
FILES+= d_shift_to_narrower_type.c
+FILES+= d_struct_init_nested.c
FILES+= d_type_conv1.c
FILES+= d_type_conv1.exp
FILES+= d_type_conv2.c
Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.6 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.7
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.6 Mon Dec 28 09:58:56 2020
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh Mon Dec 28 10:22:21 2020
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.6 2020/12/28 09:58:56 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.7 2020/12/28 10:22:21 rillig Exp $
#
# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -71,6 +71,8 @@ test_case check_valid c9x_recursive_init
"init, with nested union and trailing member"
test_case check_valid nested_structs "Checks nested structs"
test_case check_valid packed_structs "Checks packed structs"
+test_case check_invalid struct_init_nested \
+ "Initialization of nested structures"
test_case check_valid cast_init "Checks cast initialization"
test_case check_valid cast_init2 "Checks cast initialization as the rhs of a" \
Added files:
Index: src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c
diff -u /dev/null src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c:1.1
--- /dev/null Mon Dec 28 10:22:21 2020
+++ src/tests/usr.bin/xlint/lint1/d_struct_init_nested.c Mon Dec 28 10:22:21 2020
@@ -0,0 +1,59 @@
+# 2 "d_struct_init_nested.c"
+
+typedef enum O1 { O1C = 101 } O1;
+typedef enum O2 { O2C = 102 } O2;
+typedef enum O3 { O3C = 103 } O3;
+typedef enum I1 { I1C = 201 } I1;
+typedef enum I2 { I2C = 202 } I2;
+
+struct Inner1 {
+ I1 i1;
+};
+
+struct Outer3Inner1 {
+ O1 o1;
+ struct Inner1 inner;
+ O3 o3;
+};
+
+O1
+funcOuter3Inner1(void)
+{
+ struct Inner1 inner = {
+ I1C
+ };
+ struct Outer3Inner1 o3i1 = {
+ O1C,
+ inner,
+ O3C
+ };
+
+ return o3i1.o1;
+}
+
+struct Inner2 {
+ I1 i1;
+ I2 i2;
+};
+
+struct Outer3Inner2 {
+ O1 o1;
+ struct Inner2 inner;
+ O3 o3;
+};
+
+O1
+funcOuter3Inner2(void)
+{
+ struct Inner2 inner = {
+ I1C,
+ I2C
+ };
+ struct Outer3Inner2 o3i2 = {
+ O1C,
+ inner,
+ O3C
+ };
+
+ return o3i2.o1;
+}