1*ed9a7a85Srillig /* $NetBSD: gcc_init_compound_literal.c,v 1.8 2023/07/29 07:49:15 rillig Exp $ */ 280be8043Srillig # 3 "gcc_init_compound_literal.c" 380be8043Srillig 480be8043Srillig /* 580be8043Srillig * C99 says in 6.7.8p4: 680be8043Srillig * 780be8043Srillig * All the expressions in an initializer for an object that has static 880be8043Srillig * storage duration shall be constant expressions or string literals. 980be8043Srillig * 10d3937333Srillig * The term "constant expression" is defined in C99 6.6, where 6.6p9 allows 11d3937333Srillig * "constant expressions" in initializers to also be an "address constant". 12d3937333Srillig * Using these address constants, it is possible to reference an unnamed 13d3937333Srillig * object created by a compound literal (C99 6.5.2.5), using either an 14d3937333Srillig * explicit '&' or the implicit array-to-pointer conversion from C99 6.3.2.1. 150580bd75Srillig * 16*ed9a7a85Srillig * Before init.c 1.195 from 2021-04-17, an assertion in check_global_variable 17*ed9a7a85Srillig * failed since these temporary objects have neither storage class EXTERN nor 18*ed9a7a85Srillig * STATIC. 1980be8043Srillig */ 2080be8043Srillig 21b2baa501Srillig /* lint1-extra-flags: -X 351 */ 22b2baa501Srillig 2380be8043Srillig // Seen in sys/crypto/aes/aes_ccm.c. 2480be8043Srillig const struct { 2580be8043Srillig const unsigned char *ctxt; 2680be8043Srillig } T = { 270580bd75Srillig .ctxt = (const unsigned char[4]){ 280580bd75Srillig 1, 2, 3, 4 290580bd75Srillig }, 3080be8043Srillig }; 31d3937333Srillig 32d3937333Srillig struct node { 33d3937333Srillig int num; 34d3937333Srillig struct node *left; 35d3937333Srillig struct node *right; 36d3937333Srillig }; 37d3937333Srillig 38d3937333Srillig /* 39d3937333Srillig * Initial tree for representing the decisions in the classic number guessing 40d3937333Srillig * game often used in teaching the basics of programming. 41d3937333Srillig */ 42c83f7defSrillig /* expect+1: warning: static variable 'guess' unused [226] */ 43d3937333Srillig static const struct node guess = { 44d3937333Srillig 50, 45d3937333Srillig &(struct node){ 46d3937333Srillig 25, 47d3937333Srillig &(struct node){ 48d3937333Srillig 12, 49d3937333Srillig (void *)0, 50d3937333Srillig (void *)0, 51d3937333Srillig }, 52d3937333Srillig &(struct node){ 53d3937333Srillig 37, 54d3937333Srillig (void *)0, 55d3937333Srillig (void *)0, 56d3937333Srillig }, 57d3937333Srillig }, 58d3937333Srillig (void *)0 59d3937333Srillig }; 60