Module Name: src
Committed By: rillig
Date: Sun Feb 21 12:49:05 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp
Log Message:
lint: add more tests for C99 initialization
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.2 -r1.3 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.3 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.4
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.3 Sun Feb 21 09:19:53 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c Sun Feb 21 12:49:05 2021
@@ -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_without_braces = 3;
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);
+}
Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.2 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.3
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.2 Sun Feb 21 09:19:53 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp Sun Feb 21 12:49:05 2021
@@ -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]