From b9c85f0a2ec3e2bdf2f4f4a582ef2db4e7cf9e6b Mon Sep 17 00:00:00 2001 From: rillig Date: Fri, 17 Dec 2021 10:51:45 +0000 Subject: tests/lint: demonstrate another initialization with few braces Seen in Postfix, smtp_proto.c. --- tests/usr.bin/xlint/lint1/init.c | 22 +++++++++++++++++++++- tests/usr.bin/xlint/lint1/init.exp | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/usr.bin/xlint/lint1/init.c b/tests/usr.bin/xlint/lint1/init.c index c3968c55e53..7b20b53d30e 100644 --- a/tests/usr.bin/xlint/lint1/init.c +++ b/tests/usr.bin/xlint/lint1/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.5 2021/12/17 10:33:23 rillig Exp $ */ +/* $NetBSD: init.c,v 1.6 2021/12/17 10:51:45 rillig Exp $ */ # 3 "init.c" /* @@ -55,3 +55,23 @@ struct { } points[] = { 0, 0, 3, 0, 0, 4, 3, 4 }; + + +/* + * Initialization with fewer braces than usual, must still be accepted. + * + * TODO: Properly handle this situation; as of init.c 1.214 from 2021-12-17, + * the below initialization sets in->in_err but shouldn't. + */ +void do_nothing(void); + +struct { + void (*action_1) (void); + void (*action_2) (void); +} actions[1] = { + /* expect+1: error: cannot initialize 'struct ' from 'pointer to function(void) returning void' [185] */ + do_nothing, + /* expect+2: error: too many array initializers, expected 1 [173] */ + /* expect+1: error: cannot initialize 'struct ' from 'pointer to function(void) returning void' [185] */ + do_nothing, +}; diff --git a/tests/usr.bin/xlint/lint1/init.exp b/tests/usr.bin/xlint/lint1/init.exp index 0abd8b77ef9..acf801980a9 100644 --- a/tests/usr.bin/xlint/lint1/init.exp +++ b/tests/usr.bin/xlint/lint1/init.exp @@ -1 +1,4 @@ init.c(16): error: empty array declaration: empty_array_with_initializer [190] +init.c(73): error: cannot initialize 'struct ' from 'pointer to function(void) returning void' [185] +init.c(76): error: too many array initializers, expected 1 [173] +init.c(76): error: cannot initialize 'struct ' from 'pointer to function(void) returning void' [185] -- cgit