]> git.draconx.ca Git - cdecl99.git/blob - tests/cdecl99-c-invalid.sh
5ffb3b39a61a0b298314be7e32f23d57d0c0acc6
[cdecl99.git] / tests / cdecl99-c-invalid.sh
1 #!/bin/sh
2 #
3 # Copyright © 2012 Nick Bowler
4 #
5 # Check that cdecl99 rejects a variety of invalid declarations.
6 #
7 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
8 # This is free software: you are free to do what the fuck you want to.
9 # There is NO WARRANTY, to the extent permitted by law.
10
11 cdecl99=./cdecl99$EXEEXT
12 scriptname=$0
13
14 test_decl() {
15         cmd=$1
16         shift
17
18         if $cdecl99 -e "$cmd $*" >/dev/null 2>&1; then
19                 printf '%s: %s not rejected\n' "$scriptname" "$*" 1>&2
20                 return 1
21         fi
22
23         return 0
24 }
25
26 set -e
27 test_decl explain 'int x$'
28 test_decl declare 'x$ as int'
29 test_decl explain 'long long long x'
30 test_decl declare 'x as long long long'
31 test_decl explain 'inline int x'
32 test_decl declare 'x as inline int'
33 test_decl explain 'restrict int x'
34 test_decl declare 'x as restrict int'
35 test_decl explain 'static auto int x'
36 test_decl declare 'x as static auto int'
37 test_decl explain 'auto x'
38 test_decl declare 'x as auto'
39 test_decl explain 'void x'
40 test_decl declare 'x as void'
41 test_decl explain 'int _Complex x'
42 test_decl declare 'x as int _Complex'
43 test_decl explain 'typedef int'
44 test_decl type    'typedef int'
45 test_decl explain 'void f(...)'
46 test_decl declare 'f as function (...) returning void'
47 # XXX: While these silly void-parameter declarations are "obviously" invalid, I
48 # can't actually find a statement in the specification which forbids them.
49 test_decl explain 'void f(void, void)'
50 test_decl declare 'f as function (void, void) returning void'
51 test_decl explain 'void f(void, ...)'
52 test_decl declare 'f as function (void, ...) returning void'
53 test_decl explain 'void f(register void)'
54 test_decl declare 'f as function (register void) returning void'
55 test_decl explain 'void f(const void)'
56 test_decl declare 'f as function (const void) returning void'
57 test_decl explain 'void f(void const)'
58 test_decl declare 'f as function (void const) returning void'
59 test_decl explain 'void f(const)'
60 test_decl declare 'f as function (const) returning void'
61 test_decl explain 'void f(typedef int x)'
62 test_decl declare 'f as function (x as typedef int) returning void'
63 test_decl explain 'void f(static int x)'
64 test_decl declare 'f as function (x as static int) returning void'
65 test_decl explain 'int f(void)[1]'
66 test_decl declare 'f as function (void) returning array 1 of int'
67 test_decl explain 'inline int (void)'
68 test_decl type    'inline function (void) returning int'
69 test_decl explain 'int f(inline int g())'
70 test_decl declare 'f as function (g as inline function returning int) returning int'
71 test_decl explain 'int f(void)(void)'
72 test_decl declare 'f as function (void) returning function (void) returning int'
73 test_decl explain 'int a[0]'
74 test_decl declare 'a as array 0 of int'
75 test_decl explain 'void a[1]'
76 test_decl declare 'a as array 1 of void'
77 test_decl explain 'int a[1](void)'
78 test_decl declare 'a as array 1 of function (void) returning int'
79 test_decl explain 'int a[1nan]'
80 test_decl declare 'a as array 1nan of int'
81 test_decl explain 'int a[99999999999999999999999999999999999999999999999999999]'
82 test_decl declare 'a as array 99999999999999999999999999999999999999999999999999999 of int'
83
84 test_decl explain 'int f((x))'
85 test_decl explain 'int f(void), g(...)'
86 test_decl explain 'int f, g((x))'
87 test_decl explain 'int x, (void)'
88 test_decl explain 'int [5], (void)'
89 test_decl explain 'int ((int))'