Home | History | Annotate | Line # | Download | only in lint1
      1 # 2 "d_fold_test.c"
      2 
      3 /*
      4  * Test how expressions are handled in a context where they are tested for
      5  * truthiness, such as in the condition of an if statement.
      6  */
      7 
      8 /* lint1-extra-flags: -X 351 */
      9 
     10 struct s {
     11 	int member;
     12 };
     13 
     14 union u {
     15 	int member;
     16 };
     17 
     18 enum e {
     19 	E
     20 };
     21 
     22 struct arr {
     23 	int arr[4];
     24 };
     25 
     26 /* C99 6.2.5p2 */
     27 void if_Bool(_Bool b)			{ if (b) return; }
     28 
     29 /* C99 6.2.5p3 */
     30 void if_char(char c)			{ if (c) return; }
     31 
     32 /* C99 6.2.5p4 */
     33 void if_signed_char(signed char sc)	{ if (sc) return; }
     34 void if_short_int(short s)		{ if (s) return; }
     35 void if_int(int i)			{ if (i) return; }
     36 void if_long_int(long int l)		{ if (l) return; }
     37 void if_long_long_int(long long int ll)	{ if (ll) return; }
     38 
     39 /* C99 6.2.5p6 */
     40 void if_unsigned_char(unsigned char uc)			{ if (uc) return; }
     41 void if_unsigned_short_int(unsigned short us)		{ if (us) return; }
     42 void if_unsigned_int(unsigned int ui)			{ if (ui) return; }
     43 void if_unsigned_long_int(unsigned long int ul)		{ if (ul) return; }
     44 void if_unsigned_long_long_int(unsigned long long int ull) { if (ull) return; }
     45 
     46 /* C99 6.2.5p10 */
     47 void if_float(float f)			{ if (f) return; }
     48 void if_double(double d)		{ if (d) return; }
     49 void if_long_double(long double ld)	{ if (ld) return; }
     50 
     51 /* C99 6.2.5p11 */
     52 void if_float_Complex(float _Complex fc)		{ if (fc) return; }
     53 void if_double_Complex(double _Complex dc)		{ if (dc) return; }
     54 void if_long_double_Complex(long double _Complex ldc)	{ if (ldc) return; }
     55 
     56 /* C99 6.2.5p16 */
     57 void if_enum(enum e e)			{ if (e) return; }
     58 
     59 /* C99 6.2.5p20 */
     60 void if_array(struct arr arr)		{ if (arr.arr) return; }
     61 /* expect+2: error: controlling expressions must have scalar type [204] */
     62 /* expect+1: warning: parameter 's' unused in function 'if_struct' [231] */
     63 void if_struct(struct s s)		{ if (s) return; }
     64 /* expect+2: error: controlling expressions must have scalar type [204] */
     65 /* expect+1: warning: parameter 'u' unused in function 'if_union' [231] */
     66 void if_union(union u u)		{ if (u) return; }
     67 void if_function(void)			{ if (if_function) return; }
     68 void if_pointer(void *p)		{ if (p) return; }
     69 
     70 /* C99 6.8.5 */
     71 /* expect+2: error: controlling expressions must have scalar type [204] */
     72 /* expect+1: warning: parameter 's' unused in function 'while_struct' [231] */
     73 void while_struct(struct s s)		{ while (s) return; }
     74 /* expect+3: error: controlling expressions must have scalar type [204] */
     75 /* expect+2: warning: end-of-loop code not reached [223] */
     76 /* expect+1: warning: parameter 's' unused in function 'for_struct' [231] */
     77 void for_struct(struct s s)		{ for (;s;) return; }
     78 /* expect+2: error: controlling expressions must have scalar type [204] */
     79 /* expect+1: warning: parameter 's' unused in function 'do_while_struct' [231] */
     80 void do_while_struct(struct s s)	{ do { return; } while (s); }
     81 
     82 /* C99 6.5.15 does not require a scalar type, curiously. */
     83 /* expect+3: error: first operand of '?' must have scalar type [170] */
     84 /* expect+2: error: function 'conditional_struct' expects to return value [214] */
     85 /* expect+1: warning: parameter 's' unused in function 'conditional_struct' [231] */
     86 int conditional_struct(struct s s)	{ return s ? 1 : 2; }
     87