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 lint: add more tests for C99 initi...



details:   https://anonhg.NetBSD.org/src/rev/f7829a30584e
branches:  trunk
changeset: 952926:f7829a30584e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 21 12:49:05 2021 +0000

description:
lint: add more tests for C99 initialization

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_init.c   |  35 ++++++++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/d_c99_init.exp |   5 ++-
 2 files changed, 36 insertions(+), 4 deletions(-)

diffs (62 lines):

diff -r 90fb6567b9f6 -r f7829a30584e tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c    Sun Feb 21 12:36:38 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c    Sun Feb 21 12:49:05 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_init.c,v 1.3 2021/02/21 09:19:53 rillig Exp $    */
+/*     $NetBSD: d_c99_init.c,v 1.4 2021/02/21 12:49:05 rillig Exp $    */
 # 3 "d_c99_init.c"
 
 /*
@@ -7,7 +7,13 @@
  * See C99 6.7.8 "Initialization".
 */
 
-/* lint1-extra-flags: -p */
+
+void use(const void *);
+
+typedef struct any {
+       const void *value;
+} any;
+
 
 // C99 6.7.8p11 says "optionally enclosed in braces".  The intended
 // interpretation is "optionally enclosed in a single pair of braces".
@@ -15,3 +21,28 @@
 int scalar_with_optional_braces = { 3 };
 int scalar_with_too_many_braces = {{ 3 }};             /* expect: 176 */
 int scalar_with_too_many_initializers = { 3, 5 };      /* expect: 174 */
+
+
+// See init_using_expr, 'handing over to ASSIGN'.
+void
+struct_initialization_via_assignment(any arg)
+{
+       any local = arg;
+       use(&local);
+}
+
+// See init_using_expr, initstack_string.
+void
+initialization_by_string(void)
+{
+       any local = { "hello" };
+       use(&local);
+}
+
+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'".
+       use(&arg);
+}
diff -r 90fb6567b9f6 -r f7829a30584e tests/usr.bin/xlint/lint1/d_c99_init.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_init.exp  Sun Feb 21 12:36:38 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.exp  Sun Feb 21 12:49:05 2021 +0000
@@ -1,2 +1,3 @@
-d_c99_init.c(16): invalid initializer type int [176]
-d_c99_init.c(17): too many initializers [174]
+d_c99_init.c(22): invalid initializer type int [176]
+d_c99_init.c(23): too many initializers [174]
+d_c99_init.c(45): initialisation type mismatch (pointer to const void) and (struct any) [185]



Home | Main Index | Thread Index | Old Index