1 /* $NetBSD: fmt_expr.c,v 1.11 2023/12/03 14:26:10 rillig Exp $ */ 2 3 /* 4 * Tests for all kinds of expressions that are not directly related to unary 5 * or binary operators. 6 * 7 * See also: 8 * lsym_binary_op.c 9 * lsym_unary_op.c 10 */ 11 12 //indent input 13 { 14 // See lsym_offsetof.c. 15 malloc(offsetof(struct s, f) + 1); 16 17 // C99 compound literals use initializer braces. 18 println((const char[3]){'-', c, '\0'}); 19 x = ((struct point){0, 0}).x; 20 21 for (ln = gnodes->first; ln != NULL; ln = ln->next) 22 *(GNode **)Vector_Push(&vec) = ln->datum; 23 } 24 //indent end 25 26 //indent run-equals-input 27 28 29 /* 30 * GCC statement expressions are not supported yet. 31 */ 32 //indent input 33 { 34 int var = ({1}); 35 int var = ({ 36 1 37 }); 38 int var = ({ 39 int decl = 1; 40 stmt; 41 }); 42 } 43 //indent end 44 45 //indent run -di0 46 { 47 int var = ({1}); 48 int var = ({ 49 1 50 }); 51 int var = ({ 52 int decl = 1; 53 stmt; 54 }); 55 } 56 // exit 1 57 // error: Standard Input:7: Unbalanced parentheses 58 // warning: Standard Input:9: Extra ')' 59 //indent end 60 61 62 // A compound expression with an unknown type is indented other than one with 63 // a known type. Ideally, both cases should be treated the same. 64 //indent input 65 { 66 var = (type) { .member = value }; 67 var = (type) { value, value, value }; 68 var = (struct s) { .member = value }; 69 var = (struct s) { value, value, value }; 70 } 71 //indent end 72 73 //indent run 74 { 75 var = (type) { 76 .member = value 77 }; 78 var = (type) { 79 value, value, value 80 }; 81 var = (struct s){.member = value}; 82 var = (struct s){value, value, value}; 83 } 84 //indent end 85