Home | History | Annotate | Line # | Download | only in lint1
expr_cast.c revision 1.2
      1 /*	$NetBSD: expr_cast.c,v 1.2 2021/08/03 18:38:02 rillig Exp $	*/
      2 # 3 "expr_cast.c"
      3 
      4 /*
      5  * Tests for value conversion using a cast-expression.
      6  *
      7  * K&R C does not mention any restrictions on the target type.
      8  * C90 requires both the source type and the target type to be scalar.
      9  *
     10  * GCC allows casting to a struct type but there is no documentation about
     11  * it at https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html.  See
     12  * c-typeck.c, function build_c_cast, RECORD_OR_UNION_TYPE_P.
     13  */
     14 
     15 /* lint1-flags: -Sw */
     16 
     17 struct S {
     18 	int member;
     19 };
     20 
     21 struct S
     22 cast(void)
     23 {
     24 	struct S {
     25 		double incompatible;
     26 	} local = {
     27 		0.0
     28 	};
     29 
     30 	/* expect+2: error: invalid cast from 'struct S' to 'struct S' [147] */
     31 	/* expect+1: warning: function cast expects to return value [214] */
     32 	return (struct S)local;
     33 }
     34