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
|
// REQUIRED_ARGS: -o-
/***************** Covariance ******************/
class C1
{
void foo() @nogc;
void bar();
}
class D1 : C1
{
override void foo(); // no error
override void bar() @nogc; // no error
}
/******************************************/
// __traits(compiles)
static assert(__traits(compiles, new Object()));
void foo_compiles() {}
@nogc void test_compiles()
{
auto fp = &foo_compiles;
static assert(!__traits(compiles, foo_compiles()));
static assert(!__traits(compiles, fp()));
static assert(!__traits(compiles, (*fp)()));
static assert(!__traits(compiles, [1,2,3]));
static assert(!__traits(compiles, [1:1, 2:2]));
struct Struct {}
static assert(!__traits(compiles, new int));
static assert(!__traits(compiles, new Struct()));
static assert(!__traits(compiles, new Object()));
int* p;
static assert(!__traits(compiles, delete p));
int[int] aa;
static assert( __traits(compiles, aa[0]));
static assert(!__traits(compiles, (aa[0] = 10)));
int[] a;
static assert(!__traits(compiles, a.length = 1));
static assert(!__traits(compiles, a.length += 1));
static assert(!__traits(compiles, a.length -= 1));
static assert(!__traits(compiles, a ~= 1));
static assert(!__traits(compiles, a ~ a));
}
/******************************************/
// https://issues.dlang.org/show_bug.cgi?id=12630
void test12630() @nogc
{
// All of these declarations should cause no errors.
static const ex1 = new Exception("invalid");
//enum ex2 = new Exception("invalid");
static const arr1 = [[1,2], [3, 4]];
enum arr2 = [[1,2], [3, 4]];
//static const aa1 = [1:1, 2:2];
enum aa2 = [1:1, 2:2];
//static const v1 = aa1[1];
enum v2 = aa2[1];
Object o;
//static const del1 = (delete o).sizeof;
//enum del2 = (delete o).sizeof;
int[] a;
static const len1 = (a.length = 1).sizeof;
enum len2 = (a.length = 1).sizeof;
static const cata1 = (a ~= 1).sizeof;
enum cata2 = (a ~= 1).sizeof;
static const cat1 = (a ~ a).sizeof;
enum cat2 = (a ~ a).sizeof;
}
/******************************************/
// https://issues.dlang.org/show_bug.cgi?id=12642
static if (is(__vector(ulong[2])))
{
import core.simd;
ulong2 test12642() @nogc
{
return [0, 0];
}
}
/******************************************/
// https://issues.dlang.org/show_bug.cgi?id=13550
auto foo13550() @nogc
{
static int[] bar()
{
return new int[2];
}
return &bar;
}
// https://issues.dlang.org/show_bug.cgi?id=19285
void f(bool cond, string s) @nogc {
auto inner() { return s; }
alias Unused1 = typeof(inner); // OK
alias Unused2 = typeof(&inner); // (Does not) INFERS GC (anymore)
enum Unused3 = __traits(compiles , &inner);
}
// https://issues.dlang.org/show_bug.cgi?id=24072
version (D_SIMD) void f24072() @nogc
{
alias int4 = __vector(int[4]);
int4 b = cast(int4)[1, 2, 3, 4];
int4 c = cast(int4)[1, 2];
}
|