source: src/tests/completeTypeError.c @ ab0203df

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since ab0203df was 4d5e57b, checked in by Rob Schluntz <rschlunt@…>, 6 years ago

Prevent implicit conversion of void * to other pointer type for parameter passing

  • Property mode set to 100644
File size: 705 bytes
RevLine 
[2c57025]1void foo(int *) {}
2void bar(void *) {}
3forall(otype T) void baz(T *);
4forall(dtype T) void qux(T *);
5forall(dtype T | sized(T)) void quux(T *);
6
[f7e749f]7struct A; // incomplete
8struct B {}; // complete
9
[2c57025]10int main() {
11        int *i;
12        void *v;
13
[4d5e57b]14        A * x;
15        A * y;
16        B * x;
17        B * z;
[f7e749f]18
[2c57025]19        // okay
[0f35657]20        *i;
[4d5e57b]21        *x; // picks B
22        *z;
[2c57025]23        foo(i);
24        bar(i);
25        baz(i);
26        qux(i);
27        quux(i);
28
29        bar(v);
30        qux(v);
31
32        // bad
[0f35657]33        *v;
[4d5e57b]34        *y;
35        foo(v);
[2c57025]36        baz(v);
37        quux(v);
38}
39
[f7e749f]40
[2c57025]41forall(otype T)
42void baz(T * x) {
43        // okay
44        bar(x);
45        baz(x);
46        qux(x);
47        quux(x);
[0f35657]48        *x;
[2c57025]49}
50
51forall(dtype T)
52void qux(T * y) {
53        // okay
54        bar(y);
55        qux(y);
56
57        // bad
58        baz(y);
59        quux(y);
[0f35657]60        *y;
[2c57025]61}
62
63forall(dtype T | sized(T))
[142cf5d]64void quux(T * z) {
[2c57025]65        // okay
66        bar(z);
67        qux(z);
68        quux(z);
[0f35657]69        *z;
[2c57025]70
71        // bad
72        baz(z);
73}
Note: See TracBrowser for help on using the repository browser.