76 changes: 52 additions & 24 deletions test/runnable/testsafe.d
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ void safeunions() // improved for issue 11510
p = uud.a.a.a.a, p = uud.a.a.a.b;

// Reading overlapped pointer field is not allowed.
static assert(!__traits(compiles, { auto p = uu1.c; }));
static assert(!__traits(compiles, { auto p = uu2.c; }));
static assert(!__traits(compiles, { auto c = uu3.c; }));
static assert(!__traits(compiles, { auto c = uu4.c; }));
static assert(!__traits(compiles, { auto p = uu5.b.a; }));
static assert(!__traits(compiles, () @safe { auto p = uu1.c; }));
static assert(!__traits(compiles, () @safe { auto p = uu2.c; }));
static assert(!__traits(compiles, () @safe { auto c = uu3.c; }));
static assert(!__traits(compiles, () @safe { auto c = uu4.c; }));
static assert(!__traits(compiles, () @safe { auto p = uu5.b.a; }));
}


Expand All @@ -188,17 +188,17 @@ void safeexception()
try {}
catch(Exception e) {}

static assert(!__traits(compiles, {
static assert(!__traits(compiles, () @safe {
try {}
catch(Error e) {}
}));

static assert(!__traits(compiles, {
static assert(!__traits(compiles, () @safe {
try {}
catch(Throwable e) {}
}));

static assert(!__traits(compiles, {
static assert(!__traits(compiles, () @safe {
try {}
catch {}
}));
Expand Down Expand Up @@ -259,42 +259,42 @@ int threadlocalvar;
@safe
void takeaddr()
{
static assert(!__traits(compiles, (int x) { auto y = &x; } ));
static assert(!__traits(compiles, { int x; auto y = &x; } ));
static assert( __traits(compiles, { static int x; auto y = &x; } ));
static assert( __traits(compiles, { auto y = &threadlocalvar; } ));
static assert(!__traits(compiles, (int x) @safe { auto y = &x; } ));
static assert(!__traits(compiles, () @safe { int x; auto y = &x; } ));
static assert( __traits(compiles, () @safe { static int x; auto y = &x; } ));
static assert( __traits(compiles, () @safe { auto y = &threadlocalvar; } ));
}

__gshared int gsharedvar;

@safe
void use__gshared()
{
static assert(!__traits(compiles, { int x = gsharedvar; } ));
static assert(!__traits(compiles, () @safe { int x = gsharedvar; } ));
}

@safe
void voidinitializers()
{//http://d.puremagic.com/issues/show_bug.cgi?id=4885
static assert(!__traits(compiles, { uint* ptr = void; } ));
static assert( __traits(compiles, { uint i = void; } ));
static assert( __traits(compiles, { uint[2] a = void; } ));
static assert(!__traits(compiles, () @safe { uint* ptr = void; } ));
static assert( __traits(compiles, () @safe { uint i = void; } ));
static assert( __traits(compiles, () @safe { uint[2] a = void; } ));

struct ValueStruct { int a; }
struct NonValueStruct { int* a; }
static assert( __traits(compiles, { ValueStruct a = void; } ));
static assert(!__traits(compiles, { NonValueStruct a = void; } ));
static assert( __traits(compiles, () @safe { ValueStruct a = void; } ));
static assert(!__traits(compiles, () @safe { NonValueStruct a = void; } ));

static assert(!__traits(compiles, { uint[] a = void; } ));
static assert(!__traits(compiles, { int** a = void; } ));
static assert(!__traits(compiles, { int[int] a = void; } ));
static assert(!__traits(compiles, () @safe { uint[] a = void; } ));
static assert(!__traits(compiles, () @safe { int** a = void; } ));
static assert(!__traits(compiles, () @safe { int[int] a = void; } ));
}

@safe
void pointerindex()
{//http://d.puremagic.com/issues/show_bug.cgi?id=9195
static assert(!__traits(compiles, { int* p; auto a = p[30]; }));
static assert( __traits(compiles, { int* p; auto a = p[0]; }));
static assert(!__traits(compiles, () @safe { int* p; auto a = p[30]; }));
static assert( __traits(compiles, () @safe{ int* p; auto a = p[0]; }));
}

@safe
Expand Down Expand Up @@ -462,6 +462,34 @@ void test12502() @safe
}

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

void main() { }
@trusted auto trusted(alias fun)() { return fun(); }

@safe void func1()()
{
char[3] s = "abc";
string t = trusted!(() => cast(string)(s[]));
assert(t == "abc");
}

@safe void func2()()
{
char[3] s = "abc";
string t = trusted!(() => cast(string)(s[]));
assert(t == "abc");
}

@safe void test14162()
{
func1();
func2();
}

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

void main()
{
test14162();
}

16 changes: 8 additions & 8 deletions test/runnable/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -1372,17 +1372,17 @@ void test_getFunctionAttributes()
ref int ref_property() @property { return *(new int); }
void safe_nothrow() @safe nothrow { }

static assert(__traits(getFunctionAttributes, pure_nothrow) == tuple!("pure", "nothrow", "@system"));
static assert(__traits(getFunctionAttributes, typeof(pure_nothrow)) == tuple!("pure", "nothrow", "@system"));
static assert(__traits(getFunctionAttributes, pure_nothrow) == tuple!("pure", "nothrow", "@nogc", "@safe"));
static assert(__traits(getFunctionAttributes, typeof(pure_nothrow)) == tuple!("pure", "nothrow", "@nogc", "@safe"));

static assert(__traits(getFunctionAttributes, static_ref_property) == tuple!("@property", "ref", "@system"));
static assert(__traits(getFunctionAttributes, typeof(&static_ref_property)) == tuple!("@property", "ref", "@system"));
static assert(__traits(getFunctionAttributes, static_ref_property) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));
static assert(__traits(getFunctionAttributes, typeof(&static_ref_property)) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));

static assert(__traits(getFunctionAttributes, ref_property) == tuple!("@property", "ref", "@system"));
static assert(__traits(getFunctionAttributes, typeof(&ref_property)) == tuple!("@property", "ref", "@system"));
static assert(__traits(getFunctionAttributes, ref_property) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));
static assert(__traits(getFunctionAttributes, typeof(&ref_property)) == tuple!("pure", "nothrow", "@property", "ref", "@safe"));

static assert(__traits(getFunctionAttributes, safe_nothrow) == tuple!("nothrow", "@safe"));
static assert(__traits(getFunctionAttributes, typeof(safe_nothrow)) == tuple!("nothrow", "@safe"));
static assert(__traits(getFunctionAttributes, safe_nothrow) == tuple!("pure", "nothrow", "@nogc", "@safe"));
static assert(__traits(getFunctionAttributes, typeof(safe_nothrow)) == tuple!("pure", "nothrow", "@nogc", "@safe"));

struct S2
{
Expand Down
4 changes: 2 additions & 2 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -4915,7 +4915,7 @@ static assert(is(typeof(S5933d.x) == FuncType5933));


class C5933a { auto x() { return 0; } }
static assert(is(typeof(&(new C5933b()).x) == int delegate() pure nothrow @nogc @safe));
static assert(is(typeof(&(new C5933b()).x) == int delegate()));

class C5933b { auto x() { return 0; } }
//static assert(is(typeof((new C5933b()).x) == FuncType5933));
Expand Down Expand Up @@ -5358,7 +5358,7 @@ void test6902()
})));

int f() pure nothrow { assert(0); }
alias int T() pure nothrow;
alias int T() pure nothrow @safe @nogc;
static if(is(typeof(&f) DT == delegate))
{
static assert(is(DT* == T*)); // ok
Expand Down