Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src tests/lint: add test for array subscripts in C99 initialization



details:   https://anonhg.NetBSD.org/src/rev/20b92b48143d
branches:  trunk
changeset: 380040:20b92b48143d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 02 21:52:36 2021 +0000

description:
tests/lint: add test for array subscripts in C99 initialization

diffstat:

 distrib/sets/lists/tests/mi                  |   4 +++-
 tests/usr.bin/xlint/lint1/Makefile           |   4 +++-
 tests/usr.bin/xlint/lint1/c99_init_array.c   |  19 +++++++++++++++++++
 tests/usr.bin/xlint/lint1/c99_init_array.exp |   1 +
 4 files changed, 26 insertions(+), 2 deletions(-)

diffs (64 lines):

diff -r 2cc1b1cd279c -r 20b92b48143d distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jul 02 21:22:26 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jul 02 21:52:36 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1070 2021/06/29 21:33:08 rillig Exp $
+# $NetBSD: mi,v 1.1071 2021/07/02 21:52:36 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6107,6 +6107,8 @@
 ./usr/tests/usr.bin/xlint/lint1/Kyuafile                       tests-usr.bin-tests     compattestfile,atf,kyua
 ./usr/tests/usr.bin/xlint/lint1/c11_generic_expression.c       tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/c11_generic_expression.exp     tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/c99_init_array.c               tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/c99_init_array.exp             tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/c99_init_designator.c          tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/c99_init_designator.exp                tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/d_alignof.c                    tests-usr.bin-tests     compattestfile,atf
diff -r 2cc1b1cd279c -r 20b92b48143d tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Fri Jul 02 21:22:26 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Fri Jul 02 21:52:36 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.72 2021/06/29 21:33:09 rillig Exp $
+# $NetBSD: Makefile,v 1.73 2021/07/02 21:52:36 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   345             # see lint1/err.c
@@ -12,6 +12,8 @@ TESTS_SH=     t_integration
 FILESDIR=      ${TESTSDIR}
 FILES+=                c11_generic_expression.c
 FILES+=                c11_generic_expression.exp
+FILES+=                c99_init_array.c
+FILES+=                c99_init_array.exp
 FILES+=                c99_init_designator.c
 FILES+=                c99_init_designator.exp
 FILES+=                d_alignof.c
diff -r 2cc1b1cd279c -r 20b92b48143d tests/usr.bin/xlint/lint1/c99_init_array.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/c99_init_array.c        Fri Jul 02 21:52:36 2021 +0000
@@ -0,0 +1,19 @@
+/*     $NetBSD: c99_init_array.c,v 1.1 2021/07/02 21:52:36 rillig Exp $        */
+# 3 "c99_init_array.c"
+
+/*
+ * Test C99-style initialization of arrays.
+ */
+
+/* lint1-extra-flags: -p */
+
+// The size of the array is determined by the maximum index, not by the last
+// one mentioned.
+int arr_11[] = { [10] = 10, [0] = 0 };
+typedef int ctassert_11[sizeof(arr_11) / sizeof(arr_11[0]) == 11 ? -1 : 1];
+/* TODO: expect-1: error: negative array dimension (-1) [20] */
+
+// Without an explicit subscript designator, the subscript counts up.
+int arr_3[] = { [1] = 1, [0] = 0, 1, 2 };
+typedef int ctassert_3[sizeof(arr_3) / sizeof(arr_3[0]) == 3 ? -1 : 1];
+/* expect-1: error: negative array dimension (-1) [20] */
diff -r 2cc1b1cd279c -r 20b92b48143d tests/usr.bin/xlint/lint1/c99_init_array.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/c99_init_array.exp      Fri Jul 02 21:52:36 2021 +0000
@@ -0,0 +1,1 @@
+c99_init_array.c(18): error: negative array dimension (-1) [20]



Home | Main Index | Thread Index | Old Index