Skip to content

Commit

Permalink
[Refactoring] Divide test cases to compilable/vgcX.d and fail_compila…
Browse files Browse the repository at this point in the history
…tion/nogcX.d
  • Loading branch information
9rnsr committed May 25, 2014
1 parent 22f6912 commit e30024d
Show file tree
Hide file tree
Showing 10 changed files with 553 additions and 387 deletions.
109 changes: 31 additions & 78 deletions test/compilable/nogc.d
@@ -1,97 +1,50 @@
// REQUIRED_ARGS: -vgc
/*
TEST_OUTPUT:
---
---
*/
// REQUIRED_ARGS: -o-

// Tests special cases which do not allocate and shouldn't error
// Statically typed dynamic array literals
int[4] arr = [1,2,3,4];
/***************** Covariance ******************/

int testSArray()
class C1
{
int[4] arr = [1,2,3,4];
auto x = cast(int[4])[1,2,3,4];
return [1, 2, 3][1];
void foo() @nogc;
void bar();
}

enum int[] enumliteral = [1,2,3,4];

void testArrayLiteral()
class D1 : C1
{
void helper(int[] a){}
int[] allocate2 = [1,2,4];
int[] e = enumliteral;
helper([1,2,3]);
override void foo(); // no error
override void bar() @nogc; // no error
}

// String literal concatenation
immutable s1 = "test" ~ "string";
enum s2 = "test" ~ "string";
/******************************************/
// 12630

void testLiteral()
void test12630() @nogc
{
string s3 = "test" ~ "string";
}
// All of these declarations should cause no errors.

//Appending to user defined type is OK
void testAppend()
{
struct App
{
ref App opOpAssign(string op)(in string s)
{
return this;
}
App opBinary(string op)(in string s) const
{
return this;
}
}
static const ex1 = new Exception("invalid");
//enum ex2 = new Exception("invalid");

App a;
a ~= "test";
auto b = a ~ "test";
}
static const arr1 = [[1,2], [3, 4]];
enum arr2 = [[1,2], [3, 4]];

// mixins
mixin(int.stringof ~ " mixInt;");
static const aa1 = [1:1, 2:2];
enum aa2 = [1:1, 2:2];

// CTFE
enum ctfe1 = "test".dup ~ "abcd";
static const v1 = aa1[1];
enum v2 = aa2[1];

/*
* Can't test this with -nogc, as -nogc marks the delegate as @nogc (as it should):
* ------
* enum n = () { auto a = [1,2,3]; return a[0] + a[1] + a[2]; }();
* ------
* Correct test:
* ------
* @nogc void func()
* {
* enum n = () { auto a = [1,2,3]; return a[0] + a[1] + a[2]; }();
* }
* ------
*/
Object o;
static const del1 = (delete o).sizeof;
enum del2 = (delete o).sizeof;

// Reading .length is OK
void testLength()
{
int[] arr;
auto x = arr.length;
}

// scope prevents closure allocation
void closureHelper1(scope void delegate() d) {}
void testClosure()
{
int a;
int[] a;
static const len1 = (a.length = 1).sizeof;
enum len2 = (a.length = 1).sizeof;

void del1()
{
a++;
}
static const cata1 = (a ~= 1).sizeof;
enum cata2 = (a ~= 1).sizeof;

closureHelper1(&del1);
static const cat1 = (a ~ a).sizeof;
enum cat2 = (a ~ a).sizeof;
}

117 changes: 0 additions & 117 deletions test/compilable/nogc_warn.d

This file was deleted.

85 changes: 85 additions & 0 deletions test/compilable/vgc1.d
@@ -0,0 +1,85 @@
// REQUIRED_ARGS: -vgc -o-
// PERMUTE_ARGS:

/***************** NewExp *******************/

struct S1 { }
struct S2 { this(int); }
struct S3 { this(int) @nogc; }
struct S4 { new(size_t); }
struct S5 { @nogc new(size_t); }

/*
TEST_OUTPUT:
---
compilable/vgc1.d(27): vgc: 'new' causes gc allocation
compilable/vgc1.d(29): vgc: 'new' causes gc allocation
compilable/vgc1.d(30): vgc: 'new' causes gc allocation
compilable/vgc1.d(32): vgc: 'new' causes gc allocation
compilable/vgc1.d(33): vgc: 'new' causes gc allocation
compilable/vgc1.d(34): vgc: 'new' causes gc allocation
compilable/vgc1.d(38): vgc: 'new' causes gc allocation
---
*/

void testNew()
{
int* p1 = new int;

int[] a1 = new int[3];
int[][] a2 = new int[][](2, 3);

S1* ps1 = new S1();
S2* ps2 = new S2(1);
S3* ps3 = new S3(1);
S4* ps4 = new S4; // no error
S5* ps5 = new S5; // no error

Object o1 = new Object();
}

/*
TEST_OUTPUT:
---
compilable/vgc1.d(67): vgc: 'delete' requires gc
compilable/vgc1.d(66): vgc: 'delete' requires gc
---
*/





void testNewScope()
{
scope int* p1 = new int; // should be error

scope int[] a1 = new int[3]; // should be error
scope int[][] a2 = new int[][](2, 3); // should be error

scope S1* ps1 = new S1(); // should be error
scope S2* ps2 = new S2(1); // should be error
scope S3* ps3 = new S3(1); // should be error
scope S4* ps4 = new S4; // no error
scope S5* ps5 = new S5; // no error

scope Object o1 = new Object(); // no error
scope o2 = new Object(); // should be no error
}

/***************** DeleteExp *******************/

/*
TEST_OUTPUT:
---
compilable/vgc1.d(82): vgc: 'delete' requires gc
compilable/vgc1.d(83): vgc: 'delete' requires gc
compilable/vgc1.d(84): vgc: 'delete' requires gc
---
*/
void testDelete(int* p, Object o, S1* s)
{
delete p;
delete o;
delete s;
}

0 comments on commit e30024d

Please sign in to comment.