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