Home | History | Annotate | Line # | Download | only in lint1
decl_direct_abstract.c revision 1.8
      1 /*	$NetBSD: decl_direct_abstract.c,v 1.8 2023/03/28 14:44:34 rillig Exp $	*/
      2 # 3 "decl_direct_abstract.c"
      3 
      4 /*
      5  * Test parsing of direct-abstract-declarator (C99 6.7.6), which are a tricky
      6  * part of the C standard since they require lookahead and are so complicated
      7  * that GCC's parser dedicates 34 lines of comments to this topic.
      8  *
      9  * See msg_155.c.
     10  */
     11 
     12 /* lint1-extra-flags: -X 351 */
     13 
     14 /*
     15  * The following tests do not use int, to avoid confusion with the implicit
     16  * return type.
     17  */
     18 
     19 char func0001(short (*)(long));
     20 
     21 /* GCC says 'char (*)(short int (*)(long int))' */
     22 /* Clang says 'char (short (*)(long))' */
     23 /* cdecl says 'function (pointer to function (long) returning short) returning char' */
     24 /* expect+1: error: cannot initialize 'double' from 'pointer to function(pointer to function(long) returning short) returning char' [185] */
     25 double type_of_func0001 = func0001;
     26 
     27 char func0002(short *(long));
     28 
     29 /* GCC says 'char (*)(short int * (*)(long int))' */
     30 /* Clang says 'char (short *(*)(long))' */
     31 /* cdecl says 'syntax error' */
     32 /* FIXME: lint is wrong, it discards the 'short *' */
     33 /* expect+1: error: cannot initialize 'double' from 'pointer to function(long) returning char' [185] */
     34 double type_of_func0002 = func0002;
     35 
     36 void c99_6_7_6_example_a(int);
     37 void c99_6_7_6_example_b(int *);
     38 void c99_6_7_6_example_c(int *[3]);
     39 void c99_6_7_6_example_d(int (*)[3]);
     40 void c99_6_7_6_example_e(int (*)[*]);
     41 void c99_6_7_6_example_f(int *());
     42 void c99_6_7_6_example_g(int (*)(void));
     43 void c99_6_7_6_example_h(int (*const[])(unsigned int, ...));
     44 
     45 struct incompatible {
     46 	int member;
     47 } x;
     48 
     49 /* expect+1: ... 'pointer to function(int) returning void' ... */
     50 double type_of_c99_6_7_6_example_a = c99_6_7_6_example_a;
     51 /* expect+1: ... 'pointer to function(pointer to int) returning void' ... */
     52 double type_of_c99_6_7_6_example_b = c99_6_7_6_example_b;
     53 /* expect+1: ... 'pointer to function(pointer to pointer to int) returning void' ... */
     54 double type_of_c99_6_7_6_example_c = c99_6_7_6_example_c;
     55 /* expect+1: ... 'pointer to function(pointer to array[3] of int) returning void' ... */
     56 double type_of_c99_6_7_6_example_d = c99_6_7_6_example_d;
     57 /* expect+1: ... 'pointer to function(pointer to array[unknown_size] of int) returning void' ... */
     58 double type_of_c99_6_7_6_example_e = c99_6_7_6_example_e;
     59 /* Wrong type before decl.c 1.256 from 2022-04-01. */
     60 /* expect+1: ... 'pointer to function(pointer to function() returning pointer to int) returning void' ... */
     61 double type_of_c99_6_7_6_example_f = c99_6_7_6_example_f;
     62 /* expect+1: ... 'pointer to function(pointer to function(void) returning int) returning void' ... */
     63 double type_of_c99_6_7_6_example_g = c99_6_7_6_example_g;
     64 /* expect+1: ... 'pointer to function(pointer to const pointer to function(unsigned int, ...) returning int) returning void' ... */
     65 double type_of_c99_6_7_6_example_h = c99_6_7_6_example_h;
     66 
     67 void int_array(int[]);
     68 void int_array_3(int[3]);
     69 /* supported since cgram.y 1.363 from 2021-09-14 */
     70 void int_array_ast(int[*]);
     71 /* expect+1: error: null dimension [17] */
     72 void int_array_7_array(int[7][]);
     73 void int_array_7_array_3(int[7][3]);
     74 /* expect+1: error: null dimension [17] */
     75 void int_array_7_array_ast(int[7][*]);
     76 
     77 void int_array_array(int[][7]);
     78 void int_array_3_array(int[3][7]);
     79 /* supported since cgram.y 1.363 from 2021-09-14 */
     80 void int_array_ast_array(int[*][7]);
     81 
     82 /* expect+1: error: cannot take size/alignment of function type 'function() returning int' [144] */
     83 unsigned long size_unspecified_args = sizeof(int());
     84 /* FIXME: Must be 'of function', not 'of void'. */
     85 /* expect+1: error: cannot take size/alignment of void [146] */
     86 unsigned long size_prototype_void = sizeof(int(void));
     87 /* TODO: error: cannot take size/alignment of function type 'function(double) returning int' [144] */
     88 unsigned long size_prototype_unnamed = sizeof(int(double));
     89 /* TODO: error: cannot take size/alignment of function type 'function(double) returning int' [144] */
     90 unsigned long size_prototype_named = sizeof(int(double dbl));
     91 
     92 /* expect+2: error: cannot take size/alignment of function type 'function() returning int' [144] */
     93 /* expect+1: error: negative array dimension (-1000) [20] */
     94 int size_unspecified_args_return_int[-1000 - (int)sizeof(int())];
     95 
     96 /* expect+2: error: cannot take size/alignment of function type 'function() returning char' [144] */
     97 /* expect+1: error: negative array dimension (-1000) [20] */
     98 int size_unspecified_args_return_char[-1000 - (int)sizeof(char())];
     99 
    100 /* FIXME: 'of void' must be 'of function'. */
    101 /* expect+2: error: cannot take size/alignment of void [146] */
    102 /* expect+1: error: negative array dimension (-1000) [20] */
    103 int size_prototype_void_return_int[-1000 - (int)sizeof(int(void))];
    104 
    105 /* FIXME: 'of void' must be 'of function'. */
    106 /* expect+2: error: cannot take size/alignment of void [146] */
    107 /* expect+1: error: negative array dimension (-1000) [20] */
    108 int size_prototype_void_return_double[-1000 - (int)sizeof(double(void))];
    109 
    110 /* expect+1: error: negative array dimension (-1008) [20] */
    111 int size_prototype_unnamed_return_int[-1000 - (int)sizeof(int(double))];
    112 
    113 /* expect+1: error: negative array dimension (-1008) [20] */
    114 int size_prototype_unnamed_return_pchar[-1000 - (int)sizeof(char *(double))];
    115 
    116 /* expect+1: error: negative array dimension (-1008) [20] */
    117 int size_prototype_named_return_int[-1000 - (int)sizeof(int(double dbl))];
    118 
    119 /* expect+1: error: negative array dimension (-1008) [20] */
    120 int size_prototype_named_return_pppchar[-1000 - (int)sizeof(char ***(double dbl))];
    121 
    122 
    123 typedef struct {
    124 	char a[1];
    125 } a01;
    126 
    127 typedef struct {
    128 	char a[4];
    129 } a04;
    130 
    131 typedef struct {
    132 	char a[8];
    133 } a08;
    134 
    135 typedef struct {
    136 	char a[32];
    137 } a32;
    138 
    139 /* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a01' [144] */
    140 /* expect+1: error: negative array dimension (-1000) [20] */
    141 int unspecified_args_return_01[-1000 - (int)sizeof(a01())];
    142 /* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a04' [144] */
    143 /* expect+1: error: negative array dimension (-1000) [20] */
    144 int unspecified_args_return_04[-1000 - (int)sizeof(a04())];
    145 /* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a08' [144] */
    146 /* expect+1: error: negative array dimension (-1000) [20] */
    147 int unspecified_args_return_08[-1000 - (int)sizeof(a08())];
    148 /* expect+2: error: cannot take size/alignment of function type 'function() returning struct typedef a32' [144] */
    149 /* expect+1: error: negative array dimension (-1000) [20] */
    150 int unspecified_args_return_32[-1000 - (int)sizeof(a32())];
    151 
    152 /* expect+2: error: cannot take size/alignment of void [146] */
    153 /* expect+1: error: negative array dimension (-1000) [20] */
    154 int prototype_void_return_01[-1000 - (int)sizeof(a01(void))];
    155 /* expect+2: error: cannot take size/alignment of void [146] */
    156 /* expect+1: error: negative array dimension (-1000) [20] */
    157 int prototype_void_return_04[-1000 - (int)sizeof(a04(void))];
    158 /* expect+2: error: cannot take size/alignment of void [146] */
    159 /* expect+1: error: negative array dimension (-1000) [20] */
    160 int prototype_void_return_08[-1000 - (int)sizeof(a08(void))];
    161 /* expect+2: error: cannot take size/alignment of void [146] */
    162 /* expect+1: error: negative array dimension (-1000) [20] */
    163 int prototype_void_return_32[-1000 - (int)sizeof(a32(void))];
    164 
    165 /* expect+1: error: negative array dimension (-1001) [20] */
    166 int prototype_unnamed_01_return_32[-1000 - (int)sizeof(a32(a01))];
    167 /* expect+1: error: negative array dimension (-1004) [20] */
    168 int prototype_unnamed_04_return_32[-1000 - (int)sizeof(a32(a04))];
    169 /* expect+1: error: negative array dimension (-1008) [20] */
    170 int prototype_unnamed_08_return_32[-1000 - (int)sizeof(a32(a08))];
    171 /* expect+2: error: cannot take size/alignment of function type 'function(struct typedef a32) returning struct typedef a32' [144] */
    172 /* expect+1: error: negative array dimension (-1000) [20] */
    173 int prototype_unnamed_32_return_32[-1000 - (int)sizeof(a32(a32))];
    174 
    175 /* expect+1: error: negative array dimension (-1032) [20] */
    176 int prototype_unnamed_32_return_01[-1000 - (int)sizeof(a01(a32))];
    177 /* expect+1: error: negative array dimension (-1032) [20] */
    178 int prototype_unnamed_32_return_04[-1000 - (int)sizeof(a04(a32))];
    179 /* expect+1: error: negative array dimension (-1032) [20] */
    180 int prototype_unnamed_32_return_08[-1000 - (int)sizeof(a08(a32))];
    181 
    182 /* expect+1: error: negative array dimension (-1001) [20] */
    183 int prototype_named_01_return_32[-1000 - (int)sizeof(a32(a01 arg))];
    184 /* expect+1: error: negative array dimension (-1004) [20] */
    185 int prototype_named_04_return_32[-1000 - (int)sizeof(a32(a04 arg))];
    186 /* expect+1: error: negative array dimension (-1008) [20] */
    187 int prototype_named_08_return_32[-1000 - (int)sizeof(a32(a08 arg))];
    188 /* expect+2: error: cannot take size/alignment of function type 'function(struct typedef a32) returning struct typedef a32' [144] */
    189 /* expect+1: error: negative array dimension (-1000) [20] */
    190 int prototype_named_32_return_32[-1000 - (int)sizeof(a32(a32 arg))];
    191 
    192 /* expect+1: error: negative array dimension (-1032) [20] */
    193 int prototype_named_32_return_01[-1000 - (int)sizeof(a01(a32 arg))];
    194 /* expect+1: error: negative array dimension (-1032) [20] */
    195 int prototype_named_32_return_04[-1000 - (int)sizeof(a04(a32 arg))];
    196 /* expect+1: error: negative array dimension (-1032) [20] */
    197 int prototype_named_32_return_08[-1000 - (int)sizeof(a08(a32 arg))];
    198