Home | History | Annotate | Line # | Download | only in lint1
      1 /*	$NetBSD: msg_333.c,v 1.8 2024/11/13 04:32:49 rillig Exp $	*/
      2 # 3 "msg_333.c"
      3 
      4 // Test for message: controlling expression must be bool, not '%s' [333]
      5 //
      6 // See d_c99_bool_strict.c for many more examples.
      7 
      8 /* lint1-extra-flags: -T -X 351 */
      9 
     10 typedef _Bool bool;
     11 
     12 static enum tagged_color {
     13 	tagged_red,
     14 } e1;
     15 typedef enum {
     16 	typedef_red,
     17 } typedef_color;
     18 static typedef_color e2;
     19 
     20 const char *
     21 example(bool b, int i, const char *p)
     22 {
     23 
     24 	if (b)
     25 		return "bool";
     26 
     27 	/* expect+1: error: controlling expression must be bool, not 'int' [333] */
     28 	if (i)
     29 		return "int";
     30 
     31 	/* expect+1: error: controlling expression must be bool, not 'enum tagged_color' [333] */
     32 	if (e1)
     33 		return "tagged enum";
     34 
     35 	/* expect+1: error: controlling expression must be bool, not 'enum typedef typedef_color' [333] */
     36 	if (e2)
     37 		return "typedef enum";
     38 
     39 	/* expect+1: error: controlling expression must be bool, not 'pointer' [333] */
     40 	if (p)
     41 		return "pointer";
     42 
     43 	if (__lint_false) {
     44 		/* expect+1: warning: 'return' statement not reached [193] */
     45 		return "bool constant";
     46 	}
     47 
     48 	/* expect+1: error: controlling expression must be bool, not 'int' [333] */
     49 	if (0) {
     50 		/* expect+1: warning: 'return' statement not reached [193] */
     51 		return "integer constant";
     52 	}
     53 
     54 	return p + i;
     55 }
     56