Home | History | Annotate | Line # | Download | only in lint1
decl_direct_abstract.c revision 1.5
      1  1.5  rillig /*	$NetBSD: decl_direct_abstract.c,v 1.5 2022/04/01 22:28:21 rillig Exp $	*/
      2  1.1  rillig # 3 "decl_direct_abstract.c"
      3  1.1  rillig 
      4  1.1  rillig /*
      5  1.1  rillig  * Test parsing of direct-abstract-declarator (C99 6.7.6), which are a tricky
      6  1.1  rillig  * part of the C standard since they require lookahead and are so complicated
      7  1.1  rillig  * that GCC's parser dedicates 34 lines of comments to this topic.
      8  1.1  rillig  *
      9  1.1  rillig  * See msg_155.c.
     10  1.1  rillig  */
     11  1.1  rillig 
     12  1.1  rillig /*
     13  1.1  rillig  * The following tests do not use int, to avoid confusion with the implicit
     14  1.1  rillig  * return type.
     15  1.1  rillig  */
     16  1.1  rillig 
     17  1.1  rillig char func0001(short (*)(long));
     18  1.1  rillig 
     19  1.1  rillig /* GCC says 'char (*)(short int (*)(long int))' */
     20  1.1  rillig /* Clang says 'char (short (*)(long))' */
     21  1.1  rillig /* cdecl says 'function (pointer to function (long) returning short) returning char' */
     22  1.1  rillig /* expect+1: 'pointer to function(pointer to function(long) returning short) returning char' */
     23  1.1  rillig double type_of_func0001 = func0001;
     24  1.1  rillig 
     25  1.1  rillig char func0002(short *(long));
     26  1.1  rillig 
     27  1.1  rillig /* GCC says 'char (*)(short int * (*)(long int))' */
     28  1.1  rillig /* Clang says 'char (short *(*)(long))' */
     29  1.1  rillig /* cdecl says 'syntax error' */
     30  1.1  rillig /* FIXME: lint is wrong, it discards the 'short *' */
     31  1.1  rillig /* expect+1: 'pointer to function(long) returning char' */
     32  1.1  rillig double type_of_func0002 = func0002;
     33  1.1  rillig 
     34  1.1  rillig void c99_6_7_6_example_a(int);
     35  1.1  rillig void c99_6_7_6_example_b(int *);
     36  1.1  rillig void c99_6_7_6_example_c(int *[3]);
     37  1.1  rillig void c99_6_7_6_example_d(int (*)[3]);
     38  1.1  rillig void c99_6_7_6_example_e(int (*)[*]);
     39  1.1  rillig void c99_6_7_6_example_f(int *());
     40  1.1  rillig void c99_6_7_6_example_g(int (*)(void));
     41  1.1  rillig void c99_6_7_6_example_h(int (*const[])(unsigned int, ...));
     42  1.1  rillig 
     43  1.1  rillig struct incompatible {
     44  1.1  rillig 	int member;
     45  1.1  rillig } x;
     46  1.1  rillig 
     47  1.1  rillig /* expect+1: 'pointer to function(int) returning void' */
     48  1.1  rillig double type_of_c99_6_7_6_example_a = c99_6_7_6_example_a;
     49  1.1  rillig /* expect+1: 'pointer to function(pointer to int) returning void' */
     50  1.1  rillig double type_of_c99_6_7_6_example_b = c99_6_7_6_example_b;
     51  1.1  rillig /* expect+1: 'pointer to function(pointer to pointer to int) returning void' */
     52  1.1  rillig double type_of_c99_6_7_6_example_c = c99_6_7_6_example_c;
     53  1.1  rillig /* expect+1: 'pointer to function(pointer to array[3] of int) returning void' */
     54  1.1  rillig double type_of_c99_6_7_6_example_d = c99_6_7_6_example_d;
     55  1.1  rillig /* expect+1: 'pointer to function(pointer to array[unknown_size] of int) returning void' */
     56  1.1  rillig double type_of_c99_6_7_6_example_e = c99_6_7_6_example_e;
     57  1.5  rillig /* Wrong type before decl.c 1.256 from 2022-04-01. */
     58  1.5  rillig /* expect+1: 'pointer to function(pointer to function() returning pointer to int) returning void' */
     59  1.1  rillig double type_of_c99_6_7_6_example_f = c99_6_7_6_example_f;
     60  1.1  rillig /* expect+1: 'pointer to function(pointer to function(void) returning int) returning void' */
     61  1.1  rillig double type_of_c99_6_7_6_example_g = c99_6_7_6_example_g;
     62  1.1  rillig /* expect+1: 'pointer to function(pointer to const pointer to function(unsigned int, ...) returning int) returning void' */
     63  1.1  rillig double type_of_c99_6_7_6_example_h = c99_6_7_6_example_h;
     64  1.2  rillig 
     65  1.2  rillig void int_array(int[]);
     66  1.2  rillig void int_array_3(int[3]);
     67  1.4  rillig /* supported since cgram.y 1.363 from 2021-09-14 */
     68  1.2  rillig void int_array_ast(int[*]);
     69  1.2  rillig /* expect+1: error: null dimension [17] */
     70  1.2  rillig void int_array_7_array(int[7][]);
     71  1.2  rillig void int_array_7_array_3(int[7][3]);
     72  1.2  rillig /* expect+1: error: null dimension [17] */
     73  1.2  rillig void int_array_7_array_ast(int[7][*]);
     74  1.2  rillig 
     75  1.2  rillig void int_array_array(int[][7]);
     76  1.2  rillig void int_array_3_array(int[3][7]);
     77  1.4  rillig /* supported since cgram.y 1.363 from 2021-09-14 */
     78  1.2  rillig void int_array_ast_array(int[*][7]);
     79  1.5  rillig 
     80  1.5  rillig /* expect+1: error: cannot take size/alignment of function [144] */
     81  1.5  rillig unsigned long size_unspecified_args = sizeof(int());
     82  1.5  rillig /* FIXME: Must be 'of function', not 'of void'. */
     83  1.5  rillig /* expect+1: error: cannot take size/alignment of void [146] */
     84  1.5  rillig unsigned long size_prototype_void = sizeof(int(void));
     85  1.5  rillig /* TODO: error: cannot take size/alignment of function [144] */
     86  1.5  rillig unsigned long size_prototype_unnamed = sizeof(int(double));
     87  1.5  rillig /* TODO: error: cannot take size/alignment of function [144] */
     88  1.5  rillig unsigned long size_prototype_named = sizeof(int(double dbl));
     89