1 1.1 rillig /* $NetBSD: expr_cast.c,v 1.1 2021/08/03 18:03:54 rillig Exp $ */ 2 1.1 rillig # 3 "expr_cast.c" 3 1.1 rillig 4 1.1 rillig /* 5 1.1 rillig * Tests for value conversion using a cast-expression. 6 1.1 rillig * 7 1.1 rillig * K&R C does not mention any restrictions on the target type. 8 1.1 rillig * C90 requires both the source type and the target type to be scalar. 9 1.1 rillig */ 10 1.1 rillig 11 1.1 rillig struct S { 12 1.1 rillig int member; 13 1.1 rillig }; 14 1.1 rillig 15 1.1 rillig struct S 16 1.1 rillig cast(void) 17 1.1 rillig { 18 1.1 rillig struct S { 19 1.1 rillig double incompatible; 20 1.1 rillig } local = { 21 1.1 rillig 0.0 22 1.1 rillig }; 23 1.1 rillig /* expect-3: warning: 'local' set but not used in function 'cast' [191] */ 24 1.1 rillig /* 25 1.1 rillig * ^^ XXX: The variable _is_ used, but only in a semantically wrong 26 1.1 rillig * expression. Lint should rather warn about the invalid cast in the 27 1.1 rillig * 'return' statement, but since all C compilers since C90 are 28 1.1 rillig * required to detect this already, there is no point in duplicating 29 1.1 rillig * that work. 30 1.1 rillig */ 31 1.1 rillig 32 1.1 rillig return (struct S)local; 33 1.1 rillig } 34