]> git.draconx.ca Git - cdecl99.git/blob - tests/cdecl99-c-invalid.sh
Don't allow restrict-qualified pointers to functions.
[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 # C99§6.7.3#2: Types other than opinter types derived from object or incomplete
34 # types shall not be restrict-qualified.
35 test_decl explain 'restrict int x'
36 test_decl declare 'x as restrict int'
37 test_decl explain 'int (*restrict f)(void)'
38 test_decl declare 'f as restrict pointer to function (void) returning int'
39 test_decl explain 'static auto int x'
40 test_decl declare 'x as static auto int'
41 test_decl explain 'auto x'
42 test_decl declare 'x as auto'
43 test_decl explain 'void x'
44 test_decl declare 'x as void'
45 test_decl explain 'int _Complex x'
46 test_decl declare 'x as int _Complex'
47 test_decl explain 'typedef int'
48 test_decl type    'typedef int'
49 test_decl explain 'void f(...)'
50 test_decl declare 'f as function (...) returning void'
51 # XXX: While these silly void-parameter declarations are "obviously" invalid, I
52 # can't actually find a statement in the specification which forbids them.
53 test_decl explain 'void f(void, void)'
54 test_decl declare 'f as function (void, void) returning void'
55 test_decl explain 'void f(void, ...)'
56 test_decl declare 'f as function (void, ...) returning void'
57 test_decl explain 'void f(register void)'
58 test_decl declare 'f as function (register void) returning void'
59 test_decl explain 'void f(const void)'
60 test_decl declare 'f as function (const void) returning void'
61 test_decl explain 'void f(void const)'
62 test_decl declare 'f as function (void const) returning void'
63 test_decl explain 'void f(const)'
64 test_decl declare 'f as function (const) returning void'
65 test_decl explain 'void f(typedef int x)'
66 test_decl declare 'f as function (x as typedef int) returning void'
67 test_decl explain 'void f(static int x)'
68 test_decl declare 'f as function (x as static int) returning void'
69 test_decl explain 'int f(void)[1]'
70 test_decl declare 'f as function (void) returning array 1 of int'
71 test_decl explain 'inline int (void)'
72 test_decl type    'inline function (void) returning int'
73 test_decl explain 'int f(inline int g())'
74 test_decl declare 'f as function (g as inline function returning int) returning int'
75 test_decl explain 'int f(void)(void)'
76 test_decl declare 'f as function (void) returning function (void) returning int'
77 test_decl explain 'int a[0]'
78 test_decl declare 'a as array 0 of int'
79 test_decl explain 'void a[1]'
80 test_decl declare 'a as array 1 of void'
81 test_decl explain 'int a[1](void)'
82 test_decl declare 'a as array 1 of function (void) returning int'
83 test_decl explain 'int a[1nan]'
84 test_decl declare 'a as array 1nan of int'
85 test_decl explain 'int a[99999999999999999999999999999999999999999999999999999]'
86 test_decl declare 'a as array 99999999999999999999999999999999999999999999999999999 of int'
87
88 test_decl explain 'int f((x))'
89 test_decl explain 'int f(void), g(...)'
90 test_decl explain 'int f, g((x))'
91 test_decl explain 'int x, (void)'
92 test_decl explain 'int [5], (void)'
93 test_decl explain 'int ((int))'