]> git.draconx.ca Git - cdecl99.git/blob - tests/decl-bad.at
Convert invalid declaration test to Autotest.
[cdecl99.git] / tests / decl-bad.at
1 # Copyright © 2020 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([if cdecl99 -e '$1'; then exit 1; fi], [0], [], [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 inline on object declarations],
31   [explain inline int x], [declare x as inline int])
32
33 dnl Storage-class specifiers
34 SIMPLE_BADDECL([Reject multiple storage-class specifiers],
35   [explain static auto int x], [declare x as static auto int])
36 SIMPLE_BADDECL([Reject typedef in type names],
37   [explain typedef int], [type typedef int])
38
39 dnl Type specifiers
40 SIMPLE_BADDECL([Reject implicit int],
41   [explain auto x], [declare x as auto])
42 SIMPLE_BADDECL([Reject void declarations],
43   [explain void x], [declare x as void])
44 SIMPLE_BADDECL([Reject complex integers],
45   [explain int _Complex x], [declare x as int _Complex])
46
47 dnl C99§6.7.3p2: Types other than pointer types derived from object or
48 dnl incomplete types shall not be restrict-qualified.
49 SIMPLE_BADDECL([Reject restrict on object declarations],
50   [explain restrict int x], [declare x as restrict int])
51 SIMPLE_BADDECL([Reject restrict on function pointers],
52   [explain int (*restrict f)(void)],
53   [declare f as restrict pointer to function (void) returning int])
54
55 dnl Functions
56 SIMPLE_BADDECL([Reject ... with no formal parameters],
57   [explain void f(...)],
58   [declare f as function (...) returning void])
59
60 SIMPLE_BADDECL([Reject identifier lists with extra parentheses],
61   [explain int f((x))])
62
63 SIMPLE_BADDECL([Reject parameter types with extra parentheses],
64   [explain int ((int))])
65
66 dnl TODO: Find C&V which actually prohibits these "obviously wrong"
67 dnl declarations.
68 SIMPLE_BADDECL([Reject non-trivial void parameters],
69   [explain void f(void, void)],
70   [declare f as function (void, void) returning void],
71   [explain void f(void, ...)],
72   [declare f as function (void, ...) returning void],
73   [explain void f(register void)],
74   [declare f as function (register void) returning void],
75   [explain void f(const void)],
76   [declare f as function (const void) returning void],
77   [explain void f(void const)],
78   [declare f as function (void const) returning void])
79
80 SIMPLE_BADDECL([Reject parameters with no type specifier],
81   [explain void f(const)],
82   [declare f as function (const) returning void])
83
84 SIMPLE_BADDECL([Reject typedef in function parameters],
85   [explain void f(typedef int x)],
86   [declare f as function (x as typedef int) returning void])
87
88 SIMPLE_BADDECL([Reject static in function parameters],
89   [explain void f(static int x)],
90   [declare f as function (x as static int) returning void])
91
92 SIMPLE_BADDECL([Reject inline in function parameters],
93   [explain int f(inline int g())],
94   [declare f as function (g as inline function returning int) returning int])
95
96 SIMPLE_BADDECL([Reject inline in type names],
97   [explain inline int (void)],
98   [type inline function (void) returning int])
99
100 SIMPLE_BADDECL([Reject functions returning arrays],
101   [explain int f(void)[[1]]],
102   [declare f as function (void) returning array 1 of int])
103
104 SIMPLE_BADDECL([Reject functions returning functions],
105   [explain int f(void)(void)],
106   [declare f as function (void) returning function (void) returning int])
107
108 SIMPLE_BADDECL([Reject 0-length arrays],
109   [explain int a[[0]]],
110   [declare a as array 0 of int])
111
112 SIMPLE_BADDECL([Reject arrays of void],
113   [explain void a[[1]]],
114   [declare a as array 1 of void])
115
116 SIMPLE_BADDECL([Reject arrays of functions],
117   [explain int a[[1]](void)],
118   [declare a as array 1 of function (void) returning int])
119
120 SIMPLE_BADDECL([Reject arrays with invalid identifiers],
121   [explain int a[[1nan]]],
122   [declare a as array 1nan of int])
123
124 SIMPLE_BADDECL([Reject arrays of unusual size],
125   [explain int a[[99999999999999999999999999999999999999999999999999999]]],
126   [declare a as array 99999999999999999999999999999999999999999999999999999 of int])
127
128 SIMPLE_BADDECL([Reject bad declarators after good ones],
129   [explain int f(void), g(...)],
130   [explain int f, g((x))])
131
132 SIMPLE_BADDECL([Reject multiple declarators in type names],
133   [explain int f, g((x))],
134   [explain int x, (void)],
135   [explain int [[5]], (void)])