1 /* $NetBSD: d_gcc_compound_statements1.c,v 1.14 2023/07/02 22:56:13 rillig Exp $ */ 2 # 3 "d_gcc_compound_statements1.c" 3 4 /* GCC compound statement with expression */ 5 6 /* lint1-extra-flags: -X 351 */ 7 8 /* 9 * Compound statements are only allowed in functions, not at file scope. 10 * 11 * Before decl.c 1.283 from 2022-05-31, lint crashed with a segmentation 12 * fault due to the unused label. 13 */ 14 int invalid_gcc_statement_expression = ({ 15 unused_label: 16 3; 17 /* expect+2: error: syntax error 'labels are only valid inside a function' [249] */ 18 /* expect+1: error: cannot initialize 'int' from 'void' [185] */ 19 }); 20 21 void foo(unsigned long z) 22 { 23 z = ({ 24 unsigned long tmp; 25 tmp = 1; 26 tmp; 27 }); 28 foo(z); 29 } 30 31 /* 32 * Compound statements are only allowed in functions, not at file scope. 33 * 34 * Before decl.c 1.186 from 2021-06-19, lint crashed with a segmentation 35 * fault. 36 */ 37 int c = ({ 38 /* expect+1: error: syntax error 'return outside function' [249] */ 39 return 3; 40 }); 41 /* expect-1: error: cannot initialize 'int' from 'void' [185] */ 42 43 void 44 function(void) 45 { 46 /* 47 * Before cgram.y 1.229 from 2021-06-20, lint crashed due to the 48 * syntax error, which made an expression NULL. 49 */ 50 ({ 51 /* expect+1: error: type 'int' does not have member 'e' [101] */ 52 0->e; 53 }); 54 } 55 56 void 57 crash(void) 58 { 59 /* 60 * Before tree.c 1.418 from 2022-04-03, lint dereferenced a null 61 * pointer in do_statement_expr. 62 */ 63 ({ 64 ; 65 }); 66 } 67 68 /* 69 * Before cgram.y 1.445 from 2023-07-03, lint did not accept empty statements 70 * in GCC statement expressions. These empty statements can be generated by a 71 * disabled 'assert' macro. 72 */ 73 unsigned int 74 empty_statement(void) 75 { 76 return ({ 77 unsigned int mega = 1 << 20; 78 ; 79 mega; 80 }); 81 } 82