File: betterc.d

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (201 lines) | stat: -rw-r--r-- 3,543 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* REQUIRED_ARGS: -betterC
   PERMUTE_ARGS:
 */


void test(int ij)
{
    assert(ij);
#line 100 "anotherfile"
    assert(ij,"it is not zero");
}

/*******************************************/
// https://issues.dlang.org/show_bug.cgi?id=18010

void test1()
{
    int[10] a1 = void;
    int[10] a2 = void;
    a1[] = a2[];
}

void test2(int[] a1, int[] a2)
{
    a1[] = a2[];
}

/*******************************************/
// https://issues.dlang.org/show_bug.cgi?id=17843

struct S
{
    double d = 0.0;
    int[] x;
}

/*******************************************/

extern (C) void main()
{
    test(1);
    test18472();
    testRuntimeLowerings();
    test18457();
}

/*******************************************/
// https://issues.dlang.org/show_bug.cgi?id=17605

extern (C) void test17605()
{
    int a;
    enum bool works = __traits(compiles, { a = 1; });
    a = 1;
}

/*******************************************/
// https://issues.dlang.org/show_bug.cgi?id=18472

void test18472()
{
    version(D_LP64)
    {
        enum b = typeid(size_t) is typeid(ulong);
    }
    else
    {
        enum b = typeid(size_t) is typeid(uint);
    }

    assert(b);
}

/*******************************************/
// https://issues.dlang.org/show_bug.cgi?id=18493

struct S18493
{
    this(this) nothrow { }  // Since this is attributed with `nothrow` there should be no error about using
                            // try-catch with -betterC
    ~this() { }
}

struct S18493_2
{
    S18493 s1;
    S18493 s2;
}

/******************************************************
 * tests to ensure there is sufficient runtime support
 * in imported object.d
 */
mixin template initArray()
{
    static if (is(T == bool))
    {
        T[6] a1 = [true, false, true, true, false, true];
    }
    else static if (is(T == Sint))
    {
        T[6] a1 = [Sint(1), Sint(2), Sint(3), Sint(1), Sint(2), Sint(3)];
    }
    else
    {
        T[6] a1 = [1,2,3,1,2,3];
    }
}

struct Sint
{
    int x;
    this(int v) { x = v;}
}

void testRuntimeLowerings()
{
    // test call to `object.__equals`
    void test__equals(T)()
    {
        mixin initArray;

        assert(a1[0..3] == a1[3..$]);
    }

    test__equals!int;
    test__equals!uint;
    test__equals!long;
    test__equals!ulong;
    test__equals!short;
    test__equals!ushort;
    test__equals!byte;
    test__equals!dchar;
    test__equals!wchar;
    test__equals!ubyte;
    test__equals!char;
    test__equals!(const char);
    test__equals!bool;
    test__equals!Sint;

    // test call to `object.__cmp`
    void test__cmp(T)()
    {
        mixin initArray;

        assert(a1[0..3] >= a1[3..$]);
        assert(a1[0..3] <= a1[3..$]);
    }

    test__cmp!int;
    test__cmp!uint;
    test__cmp!long;
    test__cmp!ulong;
    test__cmp!short;
    test__cmp!ushort;
    test__cmp!byte;
    test__cmp!dchar;
    test__cmp!wchar;
    test__cmp!ubyte;
    test__cmp!char;
    test__cmp!(const char);
    test__cmp!bool;
    test__cmp!Sint;

    // test call to `object.__switch``
    auto s = "abc";
    switch(s)
    {
        case "abc":
            break;
        default:
            break;
    }
}

/**********************************************/
// https://issues.dlang.org/show_bug.cgi?id=18457

__gshared int dtor;

struct S18457
{
    int a = 3;
    ~this() { a = 0; ++dtor; }
}

S18457 myFunction()
{
    S18457 s = S18457();
    return s;
}

void test18457()
{
    {
        S18457 s = myFunction();
        assert(s.a == 3);
        assert(dtor == 0);
    }
    assert(dtor == 1);
}