Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 lint1: add test for initializing n...



details:   https://anonhg.NetBSD.org/src/rev/c98631e9b802
branches:  trunk
changeset: 1017445:c98631e9b802
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 28 10:22:21 2020 +0000

description:
lint1: add test for initializing nested structs

Discovered in var.c 1.774 from 2020-12-28.

diffstat:

 tests/usr.bin/xlint/lint1/Makefile               |   3 +-
 tests/usr.bin/xlint/lint1/d_struct_init_nested.c |  59 ++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/t_integration.sh       |   4 +-
 3 files changed, 64 insertions(+), 2 deletions(-)

diffs (98 lines):

diff -r 5c7f021dce8b -r c98631e9b802 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Mon Dec 28 09:58:56 2020 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Mon Dec 28 10:22:21 2020 +0000
@@ -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_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
diff -r 5c7f021dce8b -r c98631e9b802 tests/usr.bin/xlint/lint1/d_struct_init_nested.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/d_struct_init_nested.c  Mon Dec 28 10:22:21 2020 +0000
@@ -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;
+}
diff -r 5c7f021dce8b -r c98631e9b802 tests/usr.bin/xlint/lint1/t_integration.sh
--- a/tests/usr.bin/xlint/lint1/t_integration.sh        Mon Dec 28 09:58:56 2020 +0000
+++ b/tests/usr.bin/xlint/lint1/t_integration.sh        Mon Dec 28 10:22:21 2020 +0000
@@ -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 @@
     "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" \



Home | Main Index | Thread Index | Old Index