1 /* $NetBSD: decl_arg.c,v 1.7 2022/06/20 21:13:36 rillig Exp $ */ 2 # 3 "decl_arg.c" 3 4 /* 5 * Tests for declarations of function arguments. 6 * 7 * See arg_declaration in cgram.y. 8 */ 9 10 typedef double number; 11 12 void no_args(void); 13 void type_unnamed(double ); 14 void type_named(double arg); 15 void typedef_unnamed_prototype(number); 16 void typedef_named(number arg); 17 18 void type_qualifier(const number); 19 void type_qualifier_pointer(const number *const); 20 21 /* 22 * Just some unrealistic coverage for the grammar rule 'arg_declaration'. 23 */ 24 /* expect+6: warning: argument 'an_int' unused in function 'old_style' [231] */ 25 /* expect+5: warning: argument 'a_const_int' unused in function 'old_style' [231] */ 26 /* expect+4: warning: argument 'a_number' unused in function 'old_style' [231] */ 27 /* expect+3: warning: argument 'a_function' unused in function 'old_style' [231] */ 28 /* expect+2: warning: argument 'a_struct' unused in function 'old_style' [231] */ 29 extern void 30 old_style(an_int, a_const_int, a_number, a_function, a_struct) 31 /* expect+2: warning: empty declaration [2] */ 32 /* expect+1: error: only register valid as formal parameter storage class [9] */ 33 static; 34 /* expect+1: error: syntax error '"' [249] */ 35 static "error"; 36 /* expect+1: warning: empty declaration [2] */ 37 const; 38 /* expect+1: error: declared argument 'undeclared' is missing [53] */ 39 const undeclared; 40 /* expect+2: error: declared argument 'undeclared_initialized' is missing [53] */ 41 /* expect+1: error: cannot initialize parameter 'undeclared_initialized' [52] */ 42 const undeclared_initialized = 12345; 43 /* expect+1: warning: empty declaration [2] */ 44 int; 45 /* expect+1: warning: 'struct arg_struct' declared in argument declaration list [3] */ 46 struct arg_struct { int member; }; 47 /* expect+1: error: cannot initialize parameter 'an_int' [52] */ 48 int an_int = 12345; 49 const int a_const_int; 50 number a_number; 51 void (a_function) (number); 52 /* expect+1: warning: 'struct a_struct' declared in argument declaration list [3] */ 53 struct a_struct { int member; } a_struct; 54 { 55 } 56 57 /* 58 * Just some unrealistic coverage for the grammar rule 59 * 'notype_direct_declarator'. 60 */ 61 extern int 62 cover_notype_direct_decl(arg) 63 int arg; 64 /* expect+1: error: declared argument 'name' is missing [53] */ 65 const name; 66 /* expect+1: error: declared argument 'parenthesized_name' is missing [53] */ 67 const (parenthesized_name); 68 /* expect+1: error: declared argument 'array' is missing [53] */ 69 const array[]; 70 /* expect+1: error: declared argument 'array_size' is missing [53] */ 71 const array_size[1+1+1]; 72 /* expect+2: error: declared argument 'multi_array' is missing [53] */ 73 /* expect+1: error: null dimension [17] */ 74 const multi_array[][][][][][]; 75 /* expect+1: error: declared argument 'function' is missing [53] */ 76 const function(void); 77 /* expect+1: error: declared argument 'prefix_attribute' is missing [53] */ 78 const __attribute__((deprecated)) prefix_attribute; 79 /* expect+1: error: declared argument 'postfix_attribute' is missing [53] */ 80 const postfix_attribute __attribute__((deprecated)); 81 /* expect+1: error: declared argument 'infix_attribute' is missing [53] */ 82 const __attribute__((deprecated)) infix_attribute __attribute__((deprecated)); 83 /* The __attribute__ before the '*' is consumed by some other grammar rule. */ 84 /* expect+7: error: declared argument 'pointer_prefix_attribute' is missing [53] */ 85 const 86 __attribute__((deprecated)) 87 * 88 __attribute__((deprecated)) 89 __attribute__((deprecated)) 90 __attribute__((deprecated)) 91 pointer_prefix_attribute; 92 { 93 return arg; 94 } 95 96 void test_varargs_attribute( 97 void (*pr)(const char *, ...) 98 __attribute__((__format__(__printf__, 1, 2))) 99 ); 100 101 /* 102 * XXX: To cover the grammar rule 'direct_notype_param_decl', the parameters 103 * need to be enclosed by one more pair of parentheses than usual. 104 */ 105 void cover_direct_notype_param_decl( 106 double (identifier), 107 double ((parenthesized)), 108 double (array[]), 109 double (array_size[3]), 110 double (*)(void (function())) 111 ); 112 113 /* 114 * Just some unrealistic code to cover the grammar rule parameter_declaration. 115 */ 116 /* expect+4: error: only register valid as formal parameter storage class [9] */ 117 void cover_parameter_declaration( 118 volatile, /* 1 */ 119 double, /* 2 */ 120 static storage_class, /* 3.1 */ 121 const type_qualifier, /* 3.2 */ 122 double (identifier), /* 4 */ 123 const (*), /* 5 */ 124 double *const, /* 6 */ 125 ... 126 ); 127 128 void cover_asm_or_symbolrename_asm(void) 129 __asm("assembly code"); 130 131 void cover_asm_or_symbolrename_symbolrename(void) 132 __symbolrename(alternate_name); 133 134 // FIXME: internal error in decl.c:906 near decl_arg.c:134: length(0) 135 //void cover_abstract_declarator_typeof(void (*)(typeof(no_args))); 136