Skip to content

Commit

Permalink
fix Issue 13702 - One missed 'may cause GC allocation' error message
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jan 31, 2016
1 parent 9b0ea6e commit 8506d6b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/func.d
Expand Up @@ -1808,7 +1808,7 @@ public:
fbody = new CompoundStatement(Loc(), fbody, s);
}
}
if (returns && !fbody.isErrorStatement())
if (returns)
{
bool implicit0 = (f.next.ty == Tvoid && isMain());
Type tret = implicit0 ? Type.tint32 : f.next;
Expand All @@ -1823,6 +1823,15 @@ public:
{
ReturnStatement rs = (*returns)[i];
Expression exp = rs.exp;
if (exp.op == TOKerror)
continue;
if (tret.ty == Terror)
{
// Bugzilla 13702
exp = checkGC(sc2, exp);
continue;
}

if (!exp.implicitConvTo(tret) && parametersIntersect(exp.type))
{
if (exp.type.immutableOf().implicitConvTo(tret))
Expand Down
25 changes: 25 additions & 0 deletions test/fail_compilation/nogc3.d
Expand Up @@ -68,3 +68,28 @@ fail_compilation/nogc3.d(68): nogc3.testClosure3.bar closes over variable
int bar() { return x; }
takeDelegate3(&bar);
}

/****************** ErrorExp ***********************/

/*
TEST_OUTPUT:
---
fail_compilation/nogc3.d(86): Error: array literal in @nogc function foo13702 may cause GC allocation
fail_compilation/nogc3.d(87): Error: array literal in @nogc function foo13702 may cause GC allocation
fail_compilation/nogc3.d(93): Error: array literal in @nogc function bar13702 may cause GC allocation
fail_compilation/nogc3.d(92): Error: array literal in @nogc function bar13702 may cause GC allocation
---
*/
int[] foo13702(bool b) @nogc
{
if (b)
return [1]; // error
return 1 ~ [2]; // error
}
int[] bar13702(bool b) @nogc
{
if (b)
return [1]; // error <- no error report
auto aux = 1 ~ [2]; // error
return aux;
}

0 comments on commit 8506d6b

Please sign in to comment.