Module Name: src
Committed By: rillig
Date: Thu Mar 18 20:20:55 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp
Log Message:
tests/lint: add more examples for initialization
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.exp
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/d_c99_init.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.6 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.7
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.6 Sun Feb 21 14:19:27 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c Thu Mar 18 20:20:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_init.c,v 1.6 2021/02/21 14:19:27 rillig Exp $ */
+/* $NetBSD: d_c99_init.c,v 1.7 2021/03/18 20:20:55 rillig Exp $ */
# 3 "d_c99_init.c"
/*
@@ -47,9 +47,83 @@ void
initialization_with_redundant_braces(any arg)
{
any local = { arg }; /* expect: 185 */
- // FIXME: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".
+ // TODO: message 185 needs to be reworded to "cannot initialize '%s' from '%s'".
use(&arg);
}
+// Some of the following examples are mentioned in init.c.
+
+int number = 12345;
+
+int number_with_braces_and_comma = {
+ 12345,
+};
+
+int array_with_fixed_size[3] = {
+ 111,
+ 222,
+ 333,
+ 444, /* expect: too many array initializers */
+};
+
// See initstack_push, 'extending array of unknown size'.
-const int primes[] = { 2, 3, 5, 7, 9 };
+int array_of_unknown_size[] = {
+ 111,
+ 222,
+ 333,
+};
+
+int array_flat[2][2] = {
+ 11,
+ 12,
+ 21,
+ 22
+};
+
+int array_nested[2][2] = {
+ {
+ 11,
+ 12
+ },
+ {
+ 21,
+ 22
+ }
+};
+
+int array_with_designators[] = {
+ ['1'] = 111,
+ ['5'] = 555,
+ ['9'] = 999
+};
+
+int array_with_some_designators[] = {
+ ['1'] = 111,
+ 222,
+ ['9'] = 999
+};
+
+struct point {
+ int x;
+ int y;
+};
+
+struct point point = {
+ 3,
+ 4
+};
+
+struct point point_with_designators = {
+ .y = 4,
+ .x = 3,
+};
+
+struct point point_with_mixed_designators = {
+ .x = 3,
+ 4,
+ // FIXME: assertion failure '== ARRAY'
+ // 5,
+ .x = 3,
+};
+
+// See d_struct_init_nested.c for a more complicated example.
Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.5 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.6
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.5 Mon Feb 22 15:09:50 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp Thu Mar 18 20:20:55 2021
@@ -1,3 +1,4 @@
d_c99_init.c(22): invalid initializer type int [176]
d_c99_init.c(23): too many initializers [174]
d_c99_init.c(49): initialization type mismatch (pointer to const void) and (struct any) [185]
+d_c99_init.c(66): too many array initializers, expected 3 [173]