xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_343.c (revision d2c16d5796af7d64c26094d6e83f5c79714a35d6)
1 /*	$NetBSD: msg_343.c,v 1.11 2024/01/28 08:17:27 rillig Exp $	*/
2 # 3 "msg_343.c"
3 
4 /* Test for message: static array size requires C11 or later [343] */
5 
6 /* lint1-flags: -Sw -X 351 */
7 
8 void takes_int_pointer(int []);
9 void takes_int_pointer_with_ignored_size(int [3]);
10 /* expect+1: error: static array size requires C11 or later [343] */
11 void takes_int_array(int[static 3]);
12 /* expect+1: error: syntax error '3' [249] */
13 void takes_volatile_int_array(int[volatile 3]);
14 
15 int
returns_int_pointer(int a[])16 returns_int_pointer(int a[])
17 {
18 	return a[0];
19 }
20 
21 int
returns_int_pointer_with_ignored_size(int a[3])22 returns_int_pointer_with_ignored_size(int a[3])
23 {
24 	return a[0];
25 }
26 
27 int
28 /* expect+1: error: static array size requires C11 or later [343] */
returns_int_array(int a[static3])29 returns_int_array(int a[static 3])
30 {
31 	return a[0];
32 }
33 
34 int
35 /* expect+1: error: syntax error '3' [249] */
returns_volatile_int_array(int a[volatile3])36 returns_volatile_int_array(int a[volatile 3])
37 {
38 	/* expect+2: error: cannot dereference non-pointer type 'int' [96] */
39 	/* expect+1: error: function 'returns_volatile_int_array' expects to return value [214] */
40 	return a[0];
41 }
42 
43 /*
44  * This triggers the "Bad attribute", but for some reason, that custom error
45  * message does not make it into the actual diagnostic.
46  */
47 /* expect+2: error: syntax error ']' [249] */
48 /* expect+1: error: static array size requires C11 or later [343] */
49 void invalid_storage_class(int a[const typedef 3]);
50