<p dir="ltr"><br>
2014/02/28 23:06 Nordlöw <<a href="mailto:per.nordlow@gmail.com">per.nordlow@gmail.com</a>>:<br>
><br>
> I have a solution to Issue 388 at<br>
><br>
> <a href="https://github.com/nordlow/dmd/commits/master">https://github.com/nordlow/dmd/commits/master</a><br>
><br>
> that works nicely for my projects.<br>
><br>
> This patch however generates a handful of warnings in Phobos unittests.<br>
><br>
> All of these are IMO fixable except for one which I don't know how to fix namely the definition of assertCTFEable in exception.d<br>
><br>
> I need to change this to explicitly capture the return value of the template alias argument dg when this is non-void. My try so far was to change<br>
><br>
> version(unittest) package<br>
> @property void assertCTFEable(alias dg)()<br>
> {<br>
> static assert({ dg(); return true; }());<br>
> dg();<br>
> }<br>
><br>
> to<br>
><br>
> version(unittest) package<br>
> @property void assertCTFEable(alias dg)()<br>
> {<br>
> static assert<br>
> ({<br>
> static if (is(typeof(db()) == void)) {<br>
> dg();<br>
> } else {<br>
> auto x = dg();<br>
> }<br>
> return true;<br>
> }());<br>
> static if (is(typeof(db()) == void)) {<br>
> dg();<br>
> } else {<br>
> auto x = dg();<br>
> }<br>
> }<br>
><br>
> gives the following error when in Phobos make unittest:<br>
><br>
> std/exception.d(1392): Error: variable std.exception.assertCTFEable!(function ()<br>
> {<br>
> S[] r = array(repeat((S __ctmp1582 = 0;<br>
> , __ctmp1582).this(1), 2LU));<br>
> assert(equal(r, [(S __ctmp1591 = 0;<br>
> , __ctmp1591).this(1), (S __ctmp1592 = 0;<br>
> , __ctmp1592).this(1)]));<br>
> }<br>
> ).assertCTFEable.__lambda1.x type void is inferred from initializer (*function ()<br>
> {<br>
> S[] r = array(repeat((S __ctmp1582 = 0;<br>
> , __ctmp1582).this(1), 2LU));<br>
> assert(equal(r, [(S __ctmp1591 = 0;<br>
> , __ctmp1591).this(1), (S __ctmp1592 = 0;<br>
> , __ctmp1592).this(1)]));<br>
> }<br>
> )(), and variables cannot be of type void<br>
> std/exception.d(1392): Error: expression (*function ()<br>
> {<br>
> S[] r = array(repeat((S __ctmp1582 = 0;<br>
> , __ctmp1582).this(1), 2LU));<br>
> assert(equal(r, [(S __ctmp1591 = 0;<br>
> , __ctmp1591).this(1), (S __ctmp1592 = 0;<br>
> , __ctmp1592).this(1)]));<br>
> }<br>
> )() is void and has no value<br>
><br>
> How can I in a general way check if dg evaluates to void or not?</p>
<p dir="ltr">Maybe:</p>
<p dir="ltr">cast(void)dg();</p>
<p dir="ltr">Kenji Hara<br>
</p>