Source-Changes-HG archive

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

[src/trunk]: src tests/lint: test excess braces around initializers



details:   https://anonhg.NetBSD.org/src/rev/00a22474ba8e
branches:  trunk
changeset: 1029068:00a22474ba8e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 20 19:48:05 2021 +0000

description:
tests/lint: test excess braces around initializers

diffstat:

 distrib/sets/lists/tests/mi               |   4 +-
 tests/usr.bin/xlint/lint1/Makefile        |   4 +-
 tests/usr.bin/xlint/lint1/init_braces.c   |  63 +++++++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/init_braces.exp |   5 ++
 4 files changed, 74 insertions(+), 2 deletions(-)

diffs (112 lines):

diff -r 62b5bd49f22e -r 00a22474ba8e distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Mon Dec 20 19:34:01 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Mon Dec 20 19:48:05 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1178 2021/12/14 00:02:57 rillig Exp $
+# $NetBSD: mi,v 1.1179 2021/12/20 19:48:05 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -6490,6 +6490,8 @@
 ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/init.c                         tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/init.exp                       tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/init_braces.c                  tests-usr.bin-tests     compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/init_braces.exp                        tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/init_c90.c                     tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/init_c90.exp                   tests-usr.bin-tests     compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/lex_char.c                     tests-usr.bin-tests     compattestfile,atf
diff -r 62b5bd49f22e -r 00a22474ba8e tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Mon Dec 20 19:34:01 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Mon Dec 20 19:48:05 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.116 2021/12/16 11:00:15 rillig Exp $
+# $NetBSD: Makefile,v 1.117 2021/12/20 19:48:05 rillig Exp $
 
 NOMAN=         # defined
 MAX_MESSAGE=   348             # see lint1/err.c
@@ -191,6 +191,8 @@
 FILES+=                gcc_typeof_after_statement.exp
 FILES+=                init.c
 FILES+=                init.exp
+FILES+=                init_braces.c
+FILES+=                init_braces.exp
 FILES+=                init_c90.c
 FILES+=                init_c90.exp
 FILES+=                lex_char.c
diff -r 62b5bd49f22e -r 00a22474ba8e tests/usr.bin/xlint/lint1/init_braces.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/init_braces.c   Mon Dec 20 19:48:05 2021 +0000
@@ -0,0 +1,63 @@
+/*     $NetBSD: init_braces.c,v 1.1 2021/12/20 19:48:05 rillig Exp $   */
+# 3 "init_braces.c"
+
+/*
+ * Test initialization with excess braces around expressions.
+ *
+ * See also:
+ *     C99 6.7.8
+ *     C11 6.7.9
+ */
+
+void
+init_int(void)
+{
+       /* gcc-expect+2: error: invalid initializer */
+       /* clang-expect+1: error: array initializer must be an initializer list */
+       /* expect+2: error: {}-enclosed initializer required [181] */
+       /* expect+1: error: empty array declaration: num0 [190] */
+       int num0[] = 0;
+       int num1[] = { 1 };
+       /* gcc-expect+2: warning: braces around scalar initializer */
+       /* clang-expect+1: warning: braces around scalar initializer */
+       int num2[] = {{ 1 }};
+       /* gcc-expect+3: warning: braces around scalar initializer */
+       /* gcc-expect+2: warning: braces around scalar initializer */
+       /* clang-expect+1: warning: too many braces around scalar initializer */
+       int num3[] = {{{ 1 }}};
+       /* gcc-expect+5: warning: braces around scalar initializer */
+       /* gcc-expect+4: warning: braces around scalar initializer */
+       /* gcc-expect+3: warning: braces around scalar initializer */
+       /* clang-expect+2: warning: too many braces around scalar initializer */
+       /* clang-expect+1: warning: too many braces around scalar initializer */
+       int num4[] = {{{{ 1 }}}};
+}
+
+void
+init_string(void)
+{
+       char name0[] = "";
+       char name1[] = { "" };
+       /* gcc-expect+5: warning: braces around scalar initializer */
+       /* gcc-expect+4: warning: initialization of 'char' from 'char *' makes integer from pointer without a cast */
+       /* clang-expect+3: warning: incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [1]' */
+       /* clang-expect+2: warning: braces around scalar initializer */
+       /* expect+1: warning: illegal combination of integer (char) and pointer (pointer to char) [183] */
+       char name2[] = {{ "" }};
+       /* gcc-expect+6: warning: braces around scalar initializer */
+       /* gcc-expect+5: warning: braces around scalar initializer */
+       /* gcc-expect+4: warning: initialization of 'char' from 'char *' makes integer from pointer without a cast */
+       /* clang-expect+3: warning: too many braces around scalar initializer */
+       /* clang-expect+2: warning: incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [1]' */
+       /* expect+1: warning: illegal combination of integer (char) and pointer (pointer to char) [183] */
+       char name3[] = {{{ "" }}};
+       /* gcc-expect+8: warning: braces around scalar initializer */
+       /* gcc-expect+7: warning: braces around scalar initializer */
+       /* gcc-expect+6: warning: braces around scalar initializer */
+       /* gcc-expect+5: warning: initialization of 'char' from 'char *' makes integer from pointer without a cast */
+       /* clang-expect+4: warning: too many braces around scalar initializer */
+       /* clang-expect+3: warning: too many braces around scalar initializer */
+       /* clang-expect+2: warning: incompatible pointer to integer conversion initializing 'char' with an expression of type 'char [1]' */
+       /* expect+1: warning: illegal combination of integer (char) and pointer (pointer to char) [183] */
+       char name4[] = {{{{ "" }}}};
+}
diff -r 62b5bd49f22e -r 00a22474ba8e tests/usr.bin/xlint/lint1/init_braces.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/init_braces.exp Mon Dec 20 19:48:05 2021 +0000
@@ -0,0 +1,5 @@
+init_braces.c(19): error: {}-enclosed initializer required [181]
+init_braces.c(19): error: empty array declaration: num0 [190]
+init_braces.c(46): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
+init_braces.c(53): warning: illegal combination of integer (char) and pointer (pointer to char) [183]
+init_braces.c(62): warning: illegal combination of integer (char) and pointer (pointer to char) [183]



Home | Main Index | Thread Index | Old Index