aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/fail_compilation/reg6769.d
blob: 86e37e725fda04cbca23b4a2bcaf8c6af584c381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
TEST_OUTPUT:
---
fail_compilation/reg6769.d(14): Error: reinterpreting cast from `int[]` to `int[7]*` is not supported in CTFE
fail_compilation/reg6769.d(27):        called from here: `reg6769a([0, 1, 2, 3, 4, 5, 6])`
fail_compilation/reg6769.d(27):        while evaluating: `static assert(reg6769a([0, 1, 2, 3, 4, 5, 6]) == 1)`
fail_compilation/reg6769.d(20): Error: reinterpreting cast from `int[7]` to `int[]*` is not supported in CTFE
fail_compilation/reg6769.d(28):        called from here: `reg6769b([0, 1, 2, 3, 4, 5, 6])`
fail_compilation/reg6769.d(28):        while evaluating: `static assert(reg6769b([0, 1, 2, 3, 4, 5, 6]) == 1)`
---
*/
int reg6769a(int[] a)
{
    int[7]* b = cast(int[7]*)&a;
    return (*b)[1];
}

int reg6769b(int[7] a)
{
    int[]* b = cast(int[]*)&a;
    return (*b)[1];
}

void main()
{
    // Both should never succeed, run-time would raise a SEGV.
    static assert(reg6769a([0,1,2,3,4,5,6]) == 1);
    static assert(reg6769b([0,1,2,3,4,5,6]) == 1);
}