| 1 |
// REQUIRED_ARGS: -o- |
| 2 |
|
| 3 |
/***************** Covariance ******************/ |
| 4 |
|
| 5 |
class C1 |
| 6 |
{ |
| 7 |
void foo() @nogc; |
| 8 |
void bar(); |
| 9 |
} |
| 10 |
|
| 11 |
class D1 : C1 |
| 12 |
{ |
| 13 |
override void foo(); // no error |
| 14 |
override void bar() @nogc; // no error |
| 15 |
} |
| 16 |
|
| 17 |
/******************************************/ |
| 18 |
// __traits(compiles) |
| 19 |
|
| 20 |
static assert(__traits(compiles, new Object())); |
| 21 |
|
| 22 |
void foo_compiles() {} |
| 23 |
|
| 24 |
@nogc void test_compiles() |
| 25 |
{ |
| 26 |
auto fp = &foo_compiles; |
| 27 |
static assert(!__traits(compiles, foo_compiles())); |
| 28 |
static assert(!__traits(compiles, fp())); |
| 29 |
static assert(!__traits(compiles, (*fp)())); |
| 30 |
|
| 31 |
static assert(!__traits(compiles, [1,2,3])); |
| 32 |
static assert(!__traits(compiles, [1:1, 2:2])); |
| 33 |
|
| 34 |
struct Struct {} |
| 35 |
static assert(!__traits(compiles, new int)); |
| 36 |
static assert(!__traits(compiles, new Struct())); |
| 37 |
static assert(!__traits(compiles, new Object())); |
| 38 |
|
| 39 |
int[int] aa; |
| 40 |
static assert( __traits(compiles, aa[0])); |
| 41 |
static assert(!__traits(compiles, (aa[0] = 10))); |
| 42 |
|
| 43 |
int[] a; |
| 44 |
static assert(!__traits(compiles, a.length = 1)); |
| 45 |
static assert(!__traits(compiles, a.length += 1)); |
| 46 |
static assert(!__traits(compiles, a.length -= 1)); |
| 47 |
|
| 48 |
static assert(!__traits(compiles, a ~= 1)); |
| 49 |
static assert(!__traits(compiles, a ~ a)); |
| 50 |
} |
| 51 |
|
| 52 |
/******************************************/ |
| 53 |
// https://issues.dlang.org/show_bug.cgi?id=12630 |
| 54 |
|
| 55 |
void test12630() @nogc |
| 56 |
{ |
| 57 |
// All of these declarations should cause no errors. |
| 58 |
|
| 59 |
static const ex1 = new Exception("invalid"); |
| 60 |
//enum ex2 = new Exception("invalid"); |
| 61 |
|
| 62 |
static const arr1 = [[1,2], [3, 4]]; |
| 63 |
enum arr2 = [[1,2], [3, 4]]; |
| 64 |
|
| 65 |
//static const aa1 = [1:1, 2:2]; |
| 66 |
enum aa2 = [1:1, 2:2]; |
| 67 |
|
| 68 |
//static const v1 = aa1[1]; |
| 69 |
enum v2 = aa2[1]; |
| 70 |
|
| 71 |
Object o; |
| 72 |
//static const del1 = (delete o).sizeof; |
| 73 |
//enum del2 = (delete o).sizeof; |
| 74 |
|
| 75 |
int[] a; |
| 76 |
static const len1 = (a.length = 1).sizeof; |
| 77 |
enum len2 = (a.length = 1).sizeof; |
| 78 |
|
| 79 |
static const cata1 = (a ~= 1).sizeof; |
| 80 |
enum cata2 = (a ~= 1).sizeof; |
| 81 |
|
| 82 |
static const cat1 = (a ~ a).sizeof; |
| 83 |
enum cat2 = (a ~ a).sizeof; |
| 84 |
} |
| 85 |
|
| 86 |
/******************************************/ |
| 87 |
// https://issues.dlang.org/show_bug.cgi?id=12642 |
| 88 |
|
| 89 |
static if (is(__vector(ulong[2]))) |
| 90 |
{ |
| 91 |
import core.simd; |
| 92 |
|
| 93 |
ulong2 test12642() @nogc |
| 94 |
{ |
| 95 |
return [0, 0]; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
/******************************************/ |
| 100 |
// https://issues.dlang.org/show_bug.cgi?id=13550 |
| 101 |
|
| 102 |
auto foo13550() @nogc |
| 103 |
{ |
| 104 |
static int[] bar() |
| 105 |
{ |
| 106 |
return new int[2]; |
| 107 |
} |
| 108 |
return &bar; |
| 109 |
} |
| 110 |
|
| 111 |
// https://issues.dlang.org/show_bug.cgi?id=19285 |
| 112 |
|
| 113 |
void f(bool cond, string s) @nogc { |
| 114 |
auto inner() { return s; } |
| 115 |
alias Unused1 = typeof(inner); // OK |
| 116 |
alias Unused2 = typeof(&inner); // (Does not) INFERS GC (anymore) |
| 117 |
enum Unused3 = __traits(compiles , &inner); |
| 118 |
} |
| 119 |
|
| 120 |
// https://issues.dlang.org/show_bug.cgi?id=24072 |
| 121 |
|
| 122 |
version (D_SIMD) void f24072() @nogc |
| 123 |
{ |
| 124 |
alias int4 = __vector(int[4]); |
| 125 |
int4 b = cast(int4)[1, 2, 3, 4]; |
| 126 |
int4 c = cast(int4)[1, 2]; |
| 127 |
} |