Closed FranckRJ closed 1 year ago
Ok so the extension of the lifetime of actions was done to fix a very specific bug (throwing string literals), but then it seems that the buggy code isn't even standard compliant (you cannot copy arrays by doing a2 = a1
), so it shouldn't compile but only MSVC is standard-compliant there.
Not sure if I still want to merge this change. I guess I won't merge in for the 2.3.1 but will look at it later, because maybe it can fix other things.
This looks like the splitting out of the change from my PR, so it is useful for more than the case you referred to.
The important case is not for arrays but when we mock a function by giving it a copy to store for a return value where the signature is returned by a ref or const ref, and hence we do need to extend the life time.
I would say merge it is fine to merge now.
The important case is not for arrays but when we mock a function by giving it a copy to store for a return value where the signature is returned by a ref or const ref, and hence we do need to extend the life time.
I feel like it's even more of a niche case than the Throw one, because you either need to write the template type manually or write a lambda (with explicit return type), no ? There's nothing "built-in" that allow that in the library yet, it will only exist once your ReturnCopy
will be merged, right ?
I'm only hesitant because of the memory implications, but maybe it's a non-issue because mocks are short-lived, and users won't notice a big memory consumption increase.
I guess you're right. It's better to merge it, and maybe optimize later if we notice some issues with this dev. We could only mark some actions as "long-lived" and only keep them (like the action created by ReturnCopy
) for example.
I think you can get the Return function in some cases to take a copy at the moment if you use an explicit value type as the template arg. Can't remember exactly. Would need to check the unit tests.
Should fix #254.