Skip to content

Commit

Permalink
Test cases for 4825, 5615, escaping pointers
Browse files Browse the repository at this point in the history
Bug 4825 was fixed long ago but wasn't in the test suite.
  • Loading branch information
Don Clugston committed Jun 9, 2011
1 parent 14d37a1 commit ec2d4d6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -1333,6 +1333,26 @@ S6100 init6100(int x)
static const S6100[2] s6100a = [ init6100(1), init6100(2) ];
static assert(s6100a[0].a == 1);

/**************************************************
Bug 4825 -- failed with -inline
**************************************************/

int a4825() {
int r;
return r;
}

int b4825() {
return a4825();
}

void c4825() {
void d() {
auto e = b4825();
}
static const int f = b4825();
}

/**************************************************
Bug 6120 -- failed with -inline
**************************************************/
Expand Down Expand Up @@ -1556,3 +1576,46 @@ static assert({
assert(q is p);
return 6;
}() == 6);

/**************************************************
Reduced version of bug 5615
**************************************************/

const(char)[] passthrough(const(char)[] x) {
return x;
}

sizediff_t checkPass(Char1)(const(Char1)[] s)
{
const(Char1)[] balance = s[1..$];
return passthrough(balance).ptr - s.ptr;
}
static assert(checkPass("foobar")==1);

/**************************************************
Pointers must not escape from CTFE
**************************************************/

struct Toq {
const(char) * m;
}

Toq ptrRet(bool b) {
string x = "abc";
return Toq(b ? x[0..1].ptr: null);
}

static assert(is(typeof(compiles!(
{
enum Toq boz = ptrRet(false); // OK - ptr is null
Toq z = ptrRet(true); // OK -- ptr doesn't escape
return 4;
}()
))));

static assert(!is(typeof(compiles!(
{
enum Toq boz = ptrRet(true); // fail - ptr escapes
return 4;
}()
))));

0 comments on commit ec2d4d6

Please sign in to comment.