1 /* $NetBSD: expr_binary.c,v 1.4 2021/08/01 14:42:21 rillig Exp $ */ 2 # 3 "expr_binary.c" 3 4 /* 5 * Test binary operators. 6 */ 7 8 /* lint1-only-if: lp64 */ 9 10 struct incompatible { /* just to generate the error message */ 11 int member; 12 }; 13 void sink(struct incompatible); 14 15 /* 16 * Test the usual arithmetic conversions. 17 * 18 * C99 6.3.1.8 "Usual arithmetic conversions" 19 */ 20 void 21 cover_balance(void) 22 { 23 /* expect+1: 'pointer to void' */ 24 sink((void *)0 + 0); 25 26 /* expect+1: 'pointer to void' */ 27 sink(0 + (void *)0); 28 29 /* expect+1: 'int' */ 30 sink(1 + 1); 31 32 /* expect+1: 'const int' */ 33 sink((const int)1 + (volatile int)1); 34 35 /* expect+1: 'volatile int' */ 36 sink((volatile int)1 + (const int)1); 37 38 long double _Complex cldbl = 0.0; 39 double _Complex cdbl = 0.0; 40 float _Complex cflt = 0.0f; 41 /* expect+1: error: invalid type for _Complex [308] */ 42 _Complex invalid = 0.0; 43 44 /* expect+1: 'long double _Complex' */ 45 sink(cldbl + 0); 46 /* expect+1: 'long double _Complex' */ 47 sink(0 + cldbl); 48 /* expect+1: 'long double _Complex' */ 49 sink(cldbl + cdbl); 50 /* expect+1: 'long double _Complex' */ 51 sink(cdbl + cldbl); 52 53 /* expect+1: 'double _Complex' */ 54 sink(cdbl + 0); 55 /* expect+1: 'double _Complex' */ 56 sink(0 + cdbl); 57 /* expect+1: 'double _Complex' */ 58 sink(cdbl + cflt); 59 /* expect+1: 'double _Complex' */ 60 sink(cflt + cdbl); 61 62 /* expect+1: 'float _Complex' */ 63 sink(cflt + 0); 64 /* expect+1: 'float _Complex' */ 65 sink(0 + cflt); 66 /* expect+1: 'float _Complex' */ 67 sink(cflt + (__uint128_t)0); 68 /* expect+1: 'float _Complex' */ 69 sink((__uint128_t)0 + cflt); 70 71 /* 72 * The type specifier '_Complex' is only used during parsing, it does 73 * not make it to the expression. 74 */ 75 /* expect+1: 'double _Complex' */ 76 sink(invalid + 0); 77 78 /* expect+1: 'long double' */ 79 sink(0.0L + 0); 80 /* expect+1: 'long double' */ 81 sink(0 + 0.0L); 82 /* expect+1: 'long double' */ 83 sink(0.0L + 0.0); 84 /* expect+1: 'long double' */ 85 sink(0.0 + 0.0L); 86 87 /* expect+1: 'double' */ 88 sink(0.0 + 0); 89 /* expect+1: 'double' */ 90 sink(0 + 0.0); 91 /* expect+1: 'double' */ 92 sink(0.0 + 0.0f); 93 /* expect+1: 'double' */ 94 sink(0.0f + 0.0); 95 96 /* expect+1: 'float' */ 97 sink(0.0f + 0); 98 /* expect+1: 'float' */ 99 sink(0 + 0.0f); 100 /* expect+1: 'float' */ 101 sink(0.0f + (__uint128_t)0); 102 /* expect+1: 'float' */ 103 sink((__uint128_t)0 + 0.0f); 104 105 /* expect+1: 'unsigned long long' */ 106 sink(0ULL + 0); 107 /* expect+1: 'unsigned long long' */ 108 sink(0 + 0ULL); 109 110 /* expect+1: 'unsigned long long' */ 111 sink(0ULL + 0LL); 112 /* expect+1: 'unsigned long long' */ 113 sink(0LL + 0ULL); 114 115 /* If the bit-width is the same, prefer the unsigned variant. */ 116 /* expect+1: 'unsigned long long' */ 117 sink(0UL + 0LL); 118 /* expect+1: 'unsigned long long' */ 119 sink(0LL + 0UL); 120 } 121