[Issue 15056] [REG2.068.1] Unstored RAII struct return yields bogus error: "cannot mix core.std.stdlib.alloca() and exception handling"
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Sep 14 11:27:29 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15056
Martin Nowak <code at dawg.eu> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |code at dawg.eu
--- Comment #4 from Martin Nowak <code at dawg.eu> ---
But the error message seems correct, default arguments are passed from the
caller site and b/c of the destructor a try catch block is needed around
statements that might throw.
> This idiom allows for concise code that executes extremely fast and uses the least possible amount of stack memory
Not exactly sure why alloca doesn't work with EH handling, but I guess we need
fixed addresses for variables to unwind them.
You could pass in a buffer to avoid alloca.
ubyte[1234] buf = void;
foo(buf.ptr);
It's even possible to wrap the buffer with the function return value.
auto withBuf(size_t n, alias func, Args...)(auto ref Args args)
{
static struct Result
{
ubyte[n] __buf;
ReturnType!func val;
alias val this;
}
Result res = void;
emplace(res.val, func(res.ptr, args));
return res;
}
I'll still try to find out whether 2.068.1 broke something unintentionally.
--
More information about the Digitalmars-d-bugs
mailing list