Home | History | Annotate | Line # | Download | only in lint1
expr_cast.c revision 1.1
      1 /*	$NetBSD: expr_cast.c,v 1.1 2021/08/03 18:03:54 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 
     11 struct S {
     12 	int member;
     13 };
     14 
     15 struct S
     16 cast(void)
     17 {
     18 	struct S {
     19 		double incompatible;
     20 	} local = {
     21 		0.0
     22 	};
     23 	/* expect-3: warning: 'local' set but not used in function 'cast' [191] */
     24 	/*
     25 	 * ^^ XXX: The variable _is_ used, but only in a semantically wrong
     26 	 * expression.  Lint should rather warn about the invalid cast in the
     27 	 * 'return' statement, but since all C compilers since C90 are
     28 	 * required to detect this already, there is no point in duplicating
     29 	 * that work.
     30 	 */
     31 
     32 	return (struct S)local;
     33 }
     34