]> git.draconx.ca Git - cdecl99.git/blob - tests/decl-bad.at
Release 1.3.
[cdecl99.git] / tests / decl-bad.at
1 # Copyright © 2020, 2023 Nick Bowler
2 #
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16 AT_BANNER([Invalid C declarations])
17
18 m4_define([CHECK_BADDECL],
19   [AT_CHECK([cdecl99 -e '$1'], [1], [], [stderr])])
20
21 m4_define([SIMPLE_BADDECL],
22 [AT_SETUP([$1])
23 m4_map_sep([CHECK_BADDECL], [m4_newline], m4_cdr(m4_dquote_elt($@)))
24 AT_CLEANUP])
25
26 SIMPLE_BADDECL([Reject invalid identifiers],
27   [explain int x$], [declare x$ as int])
28 SIMPLE_BADDECL([Reject long long long],
29   [explain long long long x], [declare x as long long long])
30 SIMPLE_BADDECL([Reject long long double],
31   [explain long long double x], [declare x as long long double])
32 SIMPLE_BADDECL([Reject inline on object declarations],
33   [explain inline int x], [declare x as inline int])
34
35 dnl Storage-class specifiers
36 SIMPLE_BADDECL([Reject multiple storage-class specifiers],
37   [explain static auto int x], [declare x as static auto int])
38 SIMPLE_BADDECL([Reject typedef in type names],
39   [explain typedef int], [type typedef int])
40
41 dnl Type specifiers
42 SIMPLE_BADDECL([Reject implicit int],
43   [explain auto x], [declare x as auto])
44 SIMPLE_BADDECL([Reject void declarations],
45   [explain void x], [declare x as void])
46 SIMPLE_BADDECL([Reject complex integers],
47   [explain int   _Complex x], [declare x as int   _Complex],
48   [explain short _Complex x], [declare x as short _Complex],
49   [explain long  _Complex x], [declare x as long  _Complex],
50   [explain char  _Complex x], [declare x as char  _Complex])
51 SIMPLE_BADDECL([Reject imaginary integers],
52   [explain int   _Imaginary x], [declare x as int   _Imaginary],
53   [explain short _Imaginary x], [declare x as short _Imaginary],
54   [explain long  _Imaginary x], [declare x as long  _Imaginary],
55   [explain char  _Imaginary x], [declare x as char  _Imaginary])
56 SIMPLE_BADDECL([Reject signed floats],
57   [explain signed float x],  [declare x as signed float],
58   [explain signed double x], [declare x as signed double])
59 SIMPLE_BADDECL([Reject unsigned floats],
60   [explain unsigned float x],  [declare x as unsigned float],
61   [explain unsigned double x], [declare x as unsigned double])
62
63 dnl C99§6.7.3p2: Types other than pointer types derived from object or
64 dnl incomplete types shall not be restrict-qualified.
65 SIMPLE_BADDECL([Reject restrict on object declarations],
66   [explain restrict int x], [declare x as restrict int])
67 SIMPLE_BADDECL([Reject restrict on function pointers],
68   [explain int (*restrict f)(void)],
69   [declare f as restrict pointer to function (void) returning int])
70
71 dnl Functions
72 SIMPLE_BADDECL([Reject ... with no formal parameters],
73   [explain void f(...)],
74   [declare f as function (...) returning void])
75
76 SIMPLE_BADDECL([Reject identifier lists with extra parentheses],
77   [explain int f((x))],
78   [explain int f(())])
79
80 dnl TODO: Find C&V which actually prohibits these "obviously wrong"
81 dnl declarations.
82 SIMPLE_BADDECL([Reject non-trivial void parameters],
83   [explain void f(void, void)],
84   [declare f as function (void, void) returning void],
85   [explain void f(void, ...)],
86   [declare f as function (void, ...) returning void],
87   [explain void f(register void)],
88   [declare f as function (register void) returning void],
89   [explain void f(const void)],
90   [declare f as function (const void) returning void],
91   [explain void f(void const)],
92   [declare f as function (void const) returning void])
93
94 SIMPLE_BADDECL([Reject parameters with no type specifier],
95   [explain void f(const)],
96   [declare f as function (const) returning void])
97
98 SIMPLE_BADDECL([Reject typedef in function parameters],
99   [explain void f(typedef int x)],
100   [declare f as function (x as typedef int) returning void])
101
102 SIMPLE_BADDECL([Reject static in function parameters],
103   [explain void f(static int x)],
104   [declare f as function (x as static int) returning void])
105
106 SIMPLE_BADDECL([Reject inline in function parameters],
107   [explain int f(inline int g())],
108   [declare f as function (g as inline function returning int) returning int])
109
110 SIMPLE_BADDECL([Reject inline in type names],
111   [explain inline int (void)],
112   [type inline function (void) returning int])
113
114 SIMPLE_BADDECL([Reject functions returning arrays],
115   [explain int f(void)[[1]]],
116   [declare f as function (void) returning array 1 of int])
117
118 SIMPLE_BADDECL([Reject functions returning functions],
119   [explain int f(void)(void)],
120   [declare f as function (void) returning function (void) returning int])
121
122 SIMPLE_BADDECL([Reject 0-length arrays],
123   [explain int a[[0]]],
124   [declare a as array 0 of int])
125
126 SIMPLE_BADDECL([Reject arrays of void],
127   [explain void a[[1]]],
128   [declare a as array 1 of void])
129
130 SIMPLE_BADDECL([Reject arrays of functions],
131   [explain int a[[1]](void)],
132   [declare a as array 1 of function (void) returning int])
133
134 SIMPLE_BADDECL([Reject arrays with invalid identifiers],
135   [explain int a[[1nan]]],
136   [declare a as array 1nan of int])
137
138 SIMPLE_BADDECL([Reject arrays of unusual size],
139   [explain int a[[99999999999999999999999999999999999999999999999999999]]],
140   [declare a as array 99999999999999999999999999999999999999999999999999999 of int])
141
142 SIMPLE_BADDECL([Reject bad declarators after good ones],
143   [explain int f(void), g(...)],
144   [explain int f, g((x))])
145
146 SIMPLE_BADDECL([Reject multiple declarators in type names],
147   [explain int f, g((x))],
148   [explain int x, (void)],
149   [explain int [[5]], (void)])
150
151 SIMPLE_BADDECL([Error recovery on multiple object declaration],
152   [explain int inline x, y])
153
154 SIMPLE_BADDECL([Reject hyphens in identifiers],
155   [explain int ac-dc],
156   [explain int variable-length])