[Issue 17445] Disagreement between 'static assert' and 'static if'
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun May 28 07:05:21 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17445
--- Comment #4 from Dario Schiavon <dario.schiavon at gmail.com> ---
Stanislav, thanks for the tip. I knew about isAssignable but I had somehow
missed isCopyable, which is exactly what I needed.
However, I still cannot make my code work because of the bug shown here.
isAssignable only gives the right answer as long as I don't try to use it as a
static-if condition.
For example:
enum bool isCopyable(T) = is(typeof(() { T* a; T b = *a; }));
struct MyStruct
{
enum result = isCopyable!MyStruct;
pragma(msg, result);
//static if (result) {}
}
This code (with the static-if commented out) correctly prints true. But if I
leave the static-if in the struct's body, it prints false (DMD 2.074.0).
If the static-if is moved outside of the struct's body, or if the condition
doesn't involve the struct's name, then everything works as expected - but
that's not what I need.
--
More information about the Digitalmars-d-bugs
mailing list