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/10c1c5e746e0
branches: trunk
changeset: 1027732:10c1c5e746e0
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Dec 17 15:52:30 2021 +0000
description:
tests/lint: add more examples for initialization, from C99
diffstat:
tests/usr.bin/xlint/lint1/d_c99_init.c | 80 +++++++++++++++++++++++++++++--
tests/usr.bin/xlint/lint1/d_c99_init.exp | 53 +++++++++++----------
2 files changed, 102 insertions(+), 31 deletions(-)
diffs (188 lines):
diff -r 182e598a925d -r 10c1c5e746e0 tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c Fri Dec 17 15:29:44 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c Fri Dec 17 15:52:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: d_c99_init.c,v 1.33 2021/04/09 23:03:26 rillig Exp $ */
+/* $NetBSD: d_c99_init.c,v 1.34 2021/12/17 15:52:30 rillig Exp $ */
# 3 "d_c99_init.c"
/*
@@ -15,8 +15,9 @@
} any;
-// C99 6.7.8p11 says "optionally enclosed in braces". There is no limitation
-// on the number of brace pairs.
+// C99 6.7.8p11 says "optionally enclosed in braces". Whether this wording
+// means "a single pair of braces" or "as many pairs of braces as you want"
+// is left for interpretation to the reader.
int scalar_without_braces = 3;
int scalar_with_optional_braces = { 3 };
int scalar_with_too_many_braces = {{ 3 }};
@@ -262,12 +263,27 @@
6,
};
-int c99_6_7_8_p26_example3[4][3] = {
+
+/*
+ * ISO C99 6.7.8 provides a large list of examples for initialization,
+ * covering all tricky edge cases.
+ */
+
+int c99_6_7_8_p24_example1_i = 3.5;
+double _Complex c99_6_7_8_p24_example1_c = 5 + 3 * 1.0fi;
+
+int c99_6_7_8_p25_example2[] = { 1, 3, 5 };
+
+int c99_6_7_8_p26_example3a[4][3] = {
{ 1, 3, 5 },
{ 2, 4, 6 },
{ 3, 5, 7 },
};
+int c99_6_7_8_p26_example3b[4][3] = {
+ 1, 3, 5, 2, 4, 6, 3, 5, 7
+};
+
int c99_6_7_8_p27_example4[4][3] = {
{ 1 }, { 2 }, { 3 }, { 4 }
};
@@ -275,8 +291,8 @@
struct {
int a[3], b;
} c99_6_7_8_p28_example5[] = {
- { 1 }, /* just parsed, not checked in detail */
- 2, /* just parsed, not checked in detail */
+ { 1 },
+ 2,
};
short c99_6_7_8_p29_example6a[4][3][2] = {
@@ -304,10 +320,59 @@
}
};
+void
+c99_6_7_8_p31_example7(void)
+{
+ typedef int A[];
+
+ A a = { 1, 2 }, b = { 3, 4, 5 };
+
+ /* expect+1: error: negative array dimension (-8) [20] */
+ typedef int reveal_sizeof_a[-(int)(sizeof(a))];
+ /* expect+1: error: negative array dimension (-12) [20] */
+ typedef int reveal_sizeof_b[-(int)(sizeof(b))];
+}
+
+char c99_6_7_8_p32_example8_s1[] = "abc",
+ c99_6_7_8_p32_example8_t1[3] = "abc";
+char c99_6_7_8_p32_example8_s2[] = { 'a', 'b', 'c', '\0' },
+ c99_6_7_8_p32_example8_t2[3] = { 'a', 'b', 'c' };
+char *c99_6_7_8_p32_example8_p = "abc";
+
+enum { member_one, member_two };
+const char *c99_6_7_8_p33_example9[] = {
+ [member_two] = "member two",
+ [member_one] = "member one",
+};
+
+struct {
+ int quot, rem;
+} c99_6_7_8_p34_example10 = { .quot = 2, .rem = -1 };
+
+struct { int a[3], b; } c99_6_7_8_p35_example11[] =
+ { [0].a = {1}, [1].a[0] = 2 };
+
+int c99_6_7_8_p36_example12a[16] = {
+ 1, 3, 5, 7, 9, [16-5] = 8, 6, 4, 2, 0
+};
+
+int c99_6_7_8_p36_example12b[8] = {
+ 1, 3, 5, 7, 9, [8-5] = 8, 6, 4, 2, 0
+};
+
+union {
+ int first_member;
+ void *second_member;
+ unsigned char any_member;
+} c99_6_7_8_p38_example13 = { .any_member = 42 };
+
+
/*
* During initialization of an object of type array of unknown size, the type
* information on the symbol is updated in-place. Ensure that this happens on
* a copy of the type.
+ *
+ * C99 6.7.8p31 example 7
*/
void
ensure_array_type_is_not_modified_during_initialization(void)
@@ -324,6 +389,9 @@
case 12:
break;
}
+
+ /* expect+1: error: negative array dimension (-12) [20] */
+ typedef int reveal_sizeof_a1[-(int)(sizeof(a1))];
}
struct point unknown_member_name_beginning = {
diff -r 182e598a925d -r 10c1c5e746e0 tests/usr.bin/xlint/lint1/d_c99_init.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_init.exp Fri Dec 17 15:29:44 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.exp Fri Dec 17 15:52:30 2021 +0000
@@ -1,25 +1,28 @@
-d_c99_init.c(23): error: too many initializers [174]
-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(138): error: too many struct/union initializers [172]
-d_c99_init.c(144): error: syntax error 'designator '.member' is only for struct/union' [249]
-d_c99_init.c(217): error: array subscript cannot be > 2: 3 [168]
-d_c99_init.c(219): error: array subscript cannot be > 4: 5 [168]
-d_c99_init.c(221): error: array subscript cannot be > 1: 2 [168]
-d_c99_init.c(230): error: too many struct/union initializers [172]
-d_c99_init.c(236): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
-d_c99_init.c(321): error: duplicate case in switch: 0 [199]
-d_c99_init.c(330): error: type 'struct point' does not have member 'r' [101]
-d_c99_init.c(337): error: type 'struct point' does not have member 'r' [101]
-d_c99_init.c(344): error: type 'struct point' does not have member 'r' [101]
-d_c99_init.c(353): error: type 'union value' does not have member 'unknown_value' [101]
-d_c99_init.c(359): error: type 'union value' does not have member 'unknown_value' [101]
-d_c99_init.c(363): error: syntax error 'designator '[...]' is only for arrays' [249]
-d_c99_init.c(364): error: type 'struct point' does not have member 'member' [101]
-d_c99_init.c(370): warning: structure has no named members [65]
-d_c99_init.c(371): error: too many struct/union initializers [172]
-d_c99_init.c(376): warning: union has no named members [65]
-d_c99_init.c(377): error: too many struct/union initializers [172]
-d_c99_init.c(381): error: syntax error 'scalar type cannot use designator' [249]
-d_c99_init.c(385): error: syntax error 'scalar type cannot use designator' [249]
-d_c99_init.c(386): error: syntax error 'scalar type cannot use designator' [249]
+d_c99_init.c(24): error: too many initializers [174]
+d_c99_init.c(64): error: cannot initialize 'pointer to const void' from 'struct any' [185]
+d_c99_init.c(81): error: too many array initializers, expected 3 [173]
+d_c99_init.c(139): error: too many struct/union initializers [172]
+d_c99_init.c(145): error: syntax error 'designator '.member' is only for struct/union' [249]
+d_c99_init.c(218): error: array subscript cannot be > 2: 3 [168]
+d_c99_init.c(220): error: array subscript cannot be > 4: 5 [168]
+d_c99_init.c(222): error: array subscript cannot be > 1: 2 [168]
+d_c99_init.c(231): error: too many struct/union initializers [172]
+d_c99_init.c(237): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
+d_c99_init.c(331): error: negative array dimension (-8) [20]
+d_c99_init.c(333): error: negative array dimension (-12) [20]
+d_c99_init.c(386): error: duplicate case in switch: 0 [199]
+d_c99_init.c(394): error: negative array dimension (-12) [20]
+d_c99_init.c(398): error: type 'struct point' does not have member 'r' [101]
+d_c99_init.c(405): error: type 'struct point' does not have member 'r' [101]
+d_c99_init.c(412): error: type 'struct point' does not have member 'r' [101]
+d_c99_init.c(421): error: type 'union value' does not have member 'unknown_value' [101]
+d_c99_init.c(427): error: type 'union value' does not have member 'unknown_value' [101]
+d_c99_init.c(431): error: syntax error 'designator '[...]' is only for arrays' [249]
+d_c99_init.c(432): error: type 'struct point' does not have member 'member' [101]
+d_c99_init.c(438): warning: structure has no named members [65]
+d_c99_init.c(439): error: too many struct/union initializers [172]
+d_c99_init.c(444): warning: union has no named members [65]
+d_c99_init.c(445): error: too many struct/union initializers [172]
+d_c99_init.c(449): error: syntax error 'scalar type cannot use designator' [249]
+d_c99_init.c(453): error: syntax error 'scalar type cannot use designator' [249]
+d_c99_init.c(454): error: syntax error 'scalar type cannot use designator' [249]
Home |
Main Index |
Thread Index |
Old Index