Module Name: src
Committed By: rillig
Date: Sun Mar 28 18:48:32 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: d_c99_init.c d_c99_init.exp
Log Message:
tests/lint: add tests for initialization
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/tests/usr.bin/xlint/lint1/d_c99_init.c
cvs rdiff -u -r1.13 -r1.14 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.17 src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.18
--- src/tests/usr.bin/xlint/lint1/d_c99_init.c:1.17 Sun Mar 28 14:01:50 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.c Sun Mar 28 18:48:32 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_init.c,v 1.17 2021/03/28 14:01:50 rillig Exp $ */
+/* $NetBSD: d_c99_init.c,v 1.18 2021/03/28 18:48:32 rillig Exp $ */
# 3 "d_c99_init.c"
/*
@@ -34,6 +34,9 @@ struct_initialization_via_assignment(any
// See init_using_expr, initstack_string.
char static_duration[] = "static duration";
+signed char static_duration_signed[] = "static duration";
+unsigned char static_duration_unsigned[] = "static duration";
+int static_duration_wchar[] = L"static duration";
// See init_using_expr.
void
@@ -44,13 +47,25 @@ initialization_by_braced_string(void)
}
void
-initialization_with_redundant_braces(any arg)
+initialization_by_redundantly_braced_string(void)
+{
+ any local = {{{{ "hello" }}}};
+ use(&local);
+}
+
+/*
+ * Only scalar expressions and string literals may be enclosed by additional
+ * braces. Since 'arg' is a struct, this is a compile-time error.
+ */
+void
+initialization_with_too_many_braces(any arg)
{
any local = { arg }; /* expect: 185 */
use(&arg);
}
-// Some of the following examples are mentioned in init.c.
+// Some of the following examples are mentioned in the introduction comment
+// in init.c.
int number = 12345;
@@ -217,4 +232,14 @@ struct ends_with_unnamed_bit_field {
23456,
};
-// See d_struct_init_nested.c for a more complicated example.
+char prefixed_message[] = {
+ 'E', ':', ' ',
+ /* expect+1: illegal combination of integer (char) and pointer */
+ "message\n",
+};
+
+char message_with_suffix[] = {
+ "message",
+ /* expect+1: too many array initializers */
+ '\n',
+};
Index: src/tests/usr.bin/xlint/lint1/d_c99_init.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.13 src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.14
--- src/tests/usr.bin/xlint/lint1/d_c99_init.exp:1.13 Sun Mar 28 14:01:50 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_init.exp Sun Mar 28 18:48:32 2021
@@ -1,5 +1,7 @@
d_c99_init.c(23): error: too many initializers [174]
-d_c99_init.c(49): error: cannot initialize 'pointer to const void' from 'struct any' [185]
-d_c99_init.c(65): error: too many array initializers, expected 3 [173]
-d_c99_init.c(130): error: syntax error 'named member must only be used with struct/union' [249]
-d_c99_init.c(217): error: too many struct/union initializers [172]
+d_c99_init.c(63): error: cannot initialize 'pointer to const void' from 'struct any' [185]
+d_c99_init.c(80): error: too many array initializers, expected 3 [173]
+d_c99_init.c(145): error: syntax error 'named member must only be used with struct/union' [249]
+d_c99_init.c(232): error: too many struct/union initializers [172]
+d_c99_init.c(238): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
+d_c99_init.c(244): error: too many array initializers, expected 8 [173]