xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_181.c (revision 5008d0bca12c16e12787a9d05abe28807e12be92)
1 /*	$NetBSD: msg_181.c,v 1.7 2023/07/21 06:02:07 rillig Exp $	*/
2 # 3 "msg_181.c"
3 
4 // Test for message: {}-enclosed or constant initializer of type '%s' required [181]
5 
6 /* lint1-extra-flags: -X 351 */
7 
8 /* expect+1: error: {}-enclosed or constant initializer of type 'struct <unnamed>' required [181] */
9 struct { int x; } missing_braces = 3;
10 struct { int x; } including_braces = { 3 };
11 
12 
13 // C11 6.6p7 requires the initializer of an object with static storage duration
14 // to be a constant expression or an address constant, and a compound literal
15 // is neither.  C11 6.6p10 allows an implementation to accept "other forms of
16 // constant expressions", and GCC accepts compound literals that contain only
17 // constant expressions.
18 struct number {
19 	int value;
20 } num = (struct number){
21     .value = 3,
22 };
23 /* expect-1: error: {}-enclosed or constant initializer of type 'struct number' required [181] */
24