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 tests/lint: add more examples for ...



details:   https://anonhg.NetBSD.org/src/rev/d2b38d9d021b
branches:  trunk
changeset: 953722:d2b38d9d021b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Mar 18 20:20:55 2021 +0000

description:
tests/lint: add more examples for initialization

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_init.c   |  80 ++++++++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/d_c99_init.exp |   1 +
 2 files changed, 78 insertions(+), 3 deletions(-)

diffs (103 lines):

diff -r 31b20c932223 -r d2b38d9d021b tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c    Thu Mar 18 20:02:18 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c    Thu Mar 18 20:20:55 2021 +0000
@@ -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 @@
 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.
diff -r 31b20c932223 -r d2b38d9d021b tests/usr.bin/xlint/lint1/d_c99_init.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_init.exp  Thu Mar 18 20:02:18 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.exp  Thu Mar 18 20:20:55 2021 +0000
@@ -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]



Home | Main Index | Thread Index | Old Index