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