From 8506d6baee7fc19fc9b61aeb7a36cfe03893e139 Mon Sep 17 00:00:00 2001 From: k-hara Date: Tue, 1 Sep 2015 13:49:59 +0900 Subject: [PATCH] fix Issue 13702 - One missed 'may cause GC allocation' error message --- src/func.d | 11 ++++++++++- test/fail_compilation/nogc3.d | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/func.d b/src/func.d index 9cab11b13107..c555025603c1 100644 --- a/src/func.d +++ b/src/func.d @@ -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; @@ -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)) diff --git a/test/fail_compilation/nogc3.d b/test/fail_compilation/nogc3.d index 92a99a3df16b..981853574da1 100644 --- a/test/fail_compilation/nogc3.d +++ b/test/fail_compilation/nogc3.d @@ -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; +}