summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/compilable/extra-files/header1.d
blob: 93f05a50c31f71558122cc198f53327cb5b8e9de (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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
// REQUIRED_ARGS: -ignore
module foo.bar;

import core.vararg;

// Only compilable, declare inline
void writeln(T...)(T) {}

pragma(lib, "test");
pragma(msg, "Hello World");
pragma(linkerDirective, "/DEFAULTLIB:test2");

static assert(true, "message");

alias double mydbl;

alias fl1 = function ()
    in {}
    in (true)
    out (; true)
    out (r; true)
    out
    {
    }
    out (r)
    {
    }
    do
    {
        return 2;
    };

alias fl2 = function ()
    in (true)
    out(; true)
    out(r; true)
    {
        return 2;
    };

int testmain()
in
{
    assert(1+(2+3) == -(1 - 2*3));
}
out (result)
{
    assert(result == 0);
}
do
{
    float f = float.infinity;
    int i = cast(int) f;
    writeln(i,1,2);
    writeln(cast(int)float.max);
    assert(i == cast(int)float.max);
    assert(i == 0x80000000);
    return 0;
}

struct S { int m, n; }

template Foo(T, int V)
{
    void foo(...)
    {
        static if (is(Object _ : X!TL, alias X, TL...)) {}  // https://issues.dlang.org/show_bug.cgi?id=10044

        auto x = __traits(hasMember, Object, "noMember");
        auto y = is(Object : X!TL, alias X, TL...);
        assert(!x && !y, "message");

        S s = { 1,2 };
        auto a = [1, 2, 3];
        auto aa = [1:1, 2:2, 3:3];

        int n,m;
    }

    int bar(double d, int x)
    {
    if (d)
    {   d++;
    }
    else
        d--;

    asm
    {   naked ;
        mov EAX, 3;
    }

    for (;;)
    {
        d = d + 1;
    }

    for (int i = 0; i < 10; i++)
    {
        d = i ? d + 1 : 5;
    }

    char[] s;
    foreach (char c; s)
    {
        d *= 2;
        if (d)
        break;
        else
        continue;
    }

    switch (V)
    {
        case 1:
        case 2: break;
        case 3: goto case 1;
        case 4: goto default;
        default:
        d /= 8;
        break;
    }

        enum Label { A, B, C }
        void fswitch(Label l)
        {
            final switch (l)
            {
            case A: break;
            case B: break;
            case C: break;
            }
        }

    loop:
    while (x)
    {
        x--;
        if (x)
        break loop;
        else
        continue loop;
    }

    do
    {
        x++;
    } while (x < 10);

    try
    {
        bar(1, 2);
    }
    catch (Object o)
    {
        x++;
    }
    finally
    {
        x--;
    }

    try
        bar(1, 2);
    catch(Object o)
        x++;
    finally
        x--;

    Object o;
    synchronized (o)
    {
        x = ~x;
    }

    synchronized
    {
        x = x < 3;
    }

    with (o)
    {
        toString();
    }
    }
}

static this()
{
}

static ~this()
{
}

pure nothrow @safe @nogc static  this() {}
pure nothrow @safe @nogc static ~this() {}
static  this() pure nothrow @safe @nogc {}
static ~this() pure nothrow @safe @nogc {}

pure nothrow @safe @nogc shared static  this() {}
pure nothrow @safe @nogc shared static ~this() {}
shared static  this() pure nothrow @safe @nogc {}
shared static ~this() pure nothrow @safe @nogc {}

interface iFoo{}
class xFoo: iFoo{}

interface iFoo2{}
class xFoo2: iFoo, iFoo2{}

class Foo3
{
    this(int a, ...){}
    this(int* a){}
}

alias int myint;

static notquit = 1;

class Test
{
    void a() {}
    void b() {}
    void c() {}
    void d() {}
    void e() {}
    void f() {}
    void g() {}
    void h() {}
    void i() {}
    void j() {}
    void k() {}
    void l() {}
    void m() {}
    void n() {}
    void o() {}
    void p() {}
    void q() {}
    void r() {}
    void s() {}
    void t() {}
    void u() {}
    void v() {}
    void w() {}
    void x() {}
    void y() {}
    void z() {}

    void aa() {}
    void bb() {}
    void cc() {}
    void dd() {}
    void ee() {} // Try adding or removing some functions here to see the effect.

    template A(T) { }

    alias A!(uint) getHUint;
    alias A!(int) getHInt;
    alias A!(float) getHFloat;
    alias A!(ulong) getHUlong;
    alias A!(long) getHLong;
    alias A!(double) getHDouble;
    alias A!(byte) getHByte;
    alias A!(ubyte) getHUbyte;
    alias A!(short) getHShort;
    alias A!(ushort) getHUShort;
    alias A!(real) getHReal;

    alias void F();

    pure nothrow @safe @nogc unittest {}
    pure nothrow @safe @nogc invariant {}
    pure nothrow @safe @nogc invariant (true);
}

template templ( T )
{
    void templ( T val )
    {
        pragma( msg, "Invalid destination type." );
    }
}

static char[] charArray = [ '\"', '\'' ];

class Point
{
    auto x = 10;
    uint y = 20;
}

template Foo2(bool bar)
{
    void test()
    {
    static if(bar)
    {
        int i;
    }
    else
    {
    }
    static if(!bar)
    {
    }
    else
    {
    }
    }
}


template Foo4()
{
        void bar()
        {
        }
}

template Foo4x( T... ) {}

class Baz4
{
        mixin Foo4 foo;
        mixin Foo4x!(int, "str") foox;

        alias foo.bar baz;
}

int test(T)(T t)
{
        if (auto o = cast(Object)t) return 1;
        return 0;
}

enum x6 = 1;

bool foo6(int a, int b, int c, int d)
{
    return (a < b) != (c < d);
}

auto foo7(int x)
{
        return 5;
}

class D8{}
void func8()
{
  scope a= new D8();
}

T func9(T)() if (true)
{
    T i;
    scope(exit) i= 1;
    scope(success) i = 2;
    scope(failure) i = 3;
    return i;
}

template V10(T)
{
    void func()
    {
        for(int i,j=4; i<3;i++)
        {
        }
    }
}

int foo11(int function() fn)
{
    return fn();
}

int bar11(T)()
{
    return foo11(function int (){ return 0; });
}


struct S6360
{
    @property long weeks1() const pure nothrow { return 0; }

    @property const pure nothrow long weeks2() { return 0; }
}


struct S12
{
    /// postfix storage class and constructor
    this(int n) nothrow{}

    /// prefix storage class (==StorageClassDeclaration) and constructor
    nothrow this(string s){}
}

/// dummy
struct T12
{
    /// postfix storage class and template constructor
    this()(int args) immutable { }

    /// prefix storage class (==StorageClassDeclaration) and template constructor
    immutable this(A...)(A args){ }
}


// https://issues.dlang.org/show_bug.cgi?id=6591
import core.stdc.stdio : printf, F = FILE;

void foo6591()()
{
    import core.stdc.stdio : printf, F = FILE;
}


// https://issues.dlang.org/show_bug.cgi?id=8081
version(unittest) {
    pure nothrow unittest {}
    pure nothrow unittest {}

    public unittest {}
    extern(C) unittest {}
    align unittest {}
}


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

template Foo10334(T) if (Bar10334!()) {}                ///
template Foo10334(T) if (Bar10334!100) {}               ///
template Foo10334(T) if (Bar10334!3.14) {}              ///
template Foo10334(T) if (Bar10334!"str") {}             ///
template Foo10334(T) if (Bar10334!1.4i) {}              ///
template Foo10334(T) if (Bar10334!null) {}              ///
template Foo10334(T) if (Bar10334!true) {}              ///
template Foo10334(T) if (Bar10334!false) {}             ///
template Foo10334(T) if (Bar10334!'A') {}               ///
template Foo10334(T) if (Bar10334!int) {}               ///
template Foo10334(T) if (Bar10334!string) {}            ///
template Foo10334(T) if (Bar10334!wstring) {}           ///
template Foo10334(T) if (Bar10334!dstring) {}           ///
template Foo10334(T) if (Bar10334!this) {}              ///
template Foo10334(T) if (Bar10334!([1,2,3])) {}         ///
template Foo10334(T) if (Bar10334!(Baz10334!())) {}     ///
template Foo10334(T) if (Bar10334!(Baz10334!T)) {}      ///
template Foo10334(T) if (Bar10334!(Baz10334!100)) {}    ///
template Foo10334(T) if (Bar10334!(.foo)) {}            ///
template Foo10334(T) if (Bar10334!(const int)) {}       ///
template Foo10334(T) if (Bar10334!(shared T)) {}        ///

template Test10334(T...) {}     ///
mixin Test10334!int a;          ///
mixin Test10334!(int,long) b;   ///
mixin Test10334!"str" c;        ///

// https://issues.dlang.org/show_bug.cgi?id=12266
auto clamp12266a(T1, T2, T3)(T1 x, T2 min_val, T3 max_val)
{
    return 0;
}
pure clamp12266b(T1, T2, T3)(T1 x, T2 min_val, T3 max_val)
{
    return 0;
}
@disable pure clamp12266c(T1, T2, T3)(T1 x, T2 min_val, T3 max_val)
{
    return 0;
}

// https://issues.dlang.org/show_bug.cgi?id=13832
alias Dg13832 = ref int delegate();

// https://issues.dlang.org/show_bug.cgi?id=16590
class TestClass {
    int aa;
    int b1, b2;
    this(int b1, int b2)
    {
        this.b1 = b1;
        this.b2 = b2;
    }

    ref foo() {
        return aa;
    }

    ref retFunc() return {
        return aa;
    }

    ~this() @trusted @disable @nogc {
    }
}

class FooA {
    protected void method42() {

    }

    ~this() @safe {
    }

}


class Bar : FooA {
    override void method42() {

   }
}

double foo() @trusted {
    int a = 5;
    return a;
}

struct Foo1(size_t Size = 42 / magic()) {

}


size_t magic() {
    return 42;
}

class Foo2A {

    immutable(FooA) Dummy = new immutable(FooA);
    private immutable pure nothrow @nogc @safe this() {

    }

}

// https://issues.dlang.org/show_bug.cgi?id=15676
struct Foo3A(T)
{
    @disable this(this);
    @disable this();
}

// return ref, return scope, return ref scope
ref int foo(return ref int a) @safe
{
    return a;
}

int* foo(return scope int* a) @safe
{
    return a;
}

ref int* foo(scope return ref int* a) @safe
{
    return a;
}

struct SafeS
{
@safe:
    ref SafeS foo() return
    {
        return this;
    }

    SafeS foo2() return scope
    {
        return this;
    }

    ref SafeS foo3() return scope
    {
        static SafeS s;
        return s;
    }

    int* p;
}

void test13x(@(10) int a, @(20) int, @(30) @(40) int[] arr...) {}

enum Test14UDA1;
struct Test14UDA2
{
    string str;
}

Test14UDA2 test14uda3(string name)
{
    return Test14UDA2(name);
}
struct Test14UDA4(string v){}

void test14x(@Test14UDA1 int, @Test14UDA2("1") int, @test14uda3("2") int, @Test14UDA4!"3" int) {}

void test15x(@(20) void delegate(int) @safe dg){}

T throwStuff(T)(T t)
{
    if (false) test13x(1, throw new Exception(""), 2);
    return t ? t : throw new Exception("Bad stuff happens!");
}

class C12344
{
    abstract int c12344(int x) in(x > 0) out(result) {assert(result > 0);};
}

interface I12344
{
    int i12344(int x) in(x > 0) out(result) {assert(result > 0);};
}