msg_204.c revision 1.6
1/* $NetBSD: msg_204.c,v 1.6 2021/04/05 01:35:34 rillig Exp $ */ 2# 3 "msg_204.c" 3 4// Test for message: controlling expressions must have scalar type [204] 5 6extern void 7extern_function(void); 8 9void (*function_pointer)(void); 10 11/* 12 * Since func.c 1.39 from 2020-12-31 18:51:28, lint had produced an error 13 * when a controlling expression was a function. Pointers to functions were 14 * ok though. 15 */ 16void 17bug_between_2020_12_31_and_2021_01_08(void) 18{ 19 if (extern_function) 20 extern_function(); 21 22 /* 23 * FIXME: For some reason, the ampersand is discarded in 24 * build_address. This only has a visible effect if the 25 * t_spec in check_controlling_expression is evaluated too early, 26 * as has been the case before func.c 1.52 from 2021-01-08. 27 */ 28 if (&extern_function) 29 extern_function(); 30 31 /* This one has always been ok since pointers are scalar types. */ 32 if (function_pointer) 33 function_pointer(); 34} 35 36struct s { 37 int member; 38}; 39 40union u { 41 int member; 42}; 43 44enum e { 45 E 46}; 47 48struct arr { 49 int arr[4]; 50}; 51 52/* C99 6.2.5p2 */ 53void if_Bool(_Bool b) { if (b) return; } 54 55/* C99 6.2.5p3 */ 56void if_char(char c) { if (c) return; } 57 58/* C99 6.2.5p4 */ 59void if_signed_char(signed char sc) { if (sc) return; } 60void if_short_int(short s) { if (s) return; } 61void if_int(int i) { if (i) return; } 62void if_long_int(long int l) { if (l) return; } 63void if_long_long_int(long long int ll) { if (ll) return; } 64 65/* C99 6.2.5p6 */ 66void if_unsigned_char(unsigned char uc) { if (uc) return; } 67void if_unsigned_short_int(unsigned short us) { if (us) return; } 68void if_unsigned_int(unsigned int ui) { if (ui) return; } 69void if_unsigned_long_int(unsigned long int ul) { if (ul) return; } 70void if_unsigned_long_long_int(unsigned long long int ull) { if (ull) return; } 71 72/* C99 6.2.5p10 */ 73void if_float(float f) { if (f) return; } 74void if_double(double d) { if (d) return; } 75void if_long_double(long double ld) { if (ld) return; } 76 77/* C99 6.2.5p11 */ 78void if_float_Complex(float _Complex fc) { if (fc) return; } 79void if_double_Complex(double _Complex dc) { if (dc) return; } 80void if_long_double_Complex(long double _Complex ldc) { if (ldc) return; } 81 82/* C99 6.2.5p16 */ 83void if_enum(enum e e) { if (e) return; } 84 85/* C99 6.2.5p20 */ 86void if_array(struct arr arr) { if (arr.arr) return; } 87void if_struct(struct s s) { if (s) return; } /* expect: 204 *//* expect: 231 */ 88void if_union(union u u) { if (u) return; } /* expect: 204 *//* expect: 231 */ 89void if_function(void) { if (if_function) return; } 90void if_pointer(void *p) { if (p) return; } 91 92/* C99 6.8.5 */ 93void while_struct(struct s s) { while (s) return; } /* expect: 204 *//* expect: 231 */ 94void for_struct(struct s s) { for (;s;) return; } /* expect: 204 *//* expect: 223 *//* expect: 231 */ 95void do_while_struct(struct s s) { do { return; } while (s); } /* expect: 204 *//* expect: 231 */ 96 97/* 98 * C99 6.5.15 for the '?:' operator does not explicitly mention that the 99 * controlling expression must have a scalar type, curiously. 100 */ 101int conditional_struct(struct s s) { return s ? 1 : 2; } /* expect: 170 *//* expect: 214 *//* expect: 231 */ 102