From 952b904c1531d1c13ce61ee0a336d7779ccdfb36 Mon Sep 17 00:00:00 2001 From: rrhiemstar Date: Mon, 25 Nov 2024 20:19:31 +0100 Subject: [PATCH] testing return managed variables from functions. --- tests/raii.t | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/raii.t b/tests/raii.t index be0b1d8b..8f6fed6a 100644 --- a/tests/raii.t +++ b/tests/raii.t @@ -95,9 +95,12 @@ terra testcopyassignment2() end test.eq(testcopyassignment2(), 5) +--generate implementation for __move +terralib.ext.addmissing.__move(A) + printtestheader("raii.t - return from function.") terra returnone() - var a = A{4} + var a = A{4}:__move() --call __move to move resources into 'a' (make sure copy constructor is not called) return a end @@ -108,9 +111,10 @@ end test.eq(testreturnfromfun1(), 4) printtestheader("raii.t - return tuple from function.") + terra returntwo() - var a = A{4} - var b = A{5} + var a = A{4}:__move() --call __move to move resources into 'a' (make sure copy constructor is not called) + var b = A{5}:__move() --same for 'b' return a, b end @@ -118,4 +122,5 @@ terra testreturnfromfun2() var a, b = returntwo() return a.data * b.data end +print(testreturnfromfun2()) test.eq(testreturnfromfun2(), 20) \ No newline at end of file