On Friday, 29 January 2016 at 16:36:01 UTC, Steven Schveighoffer
wrote:
On 1/29/16 10:28 AM, Adrian Matoga wrote:
Code:
----
struct HasFoo { void foo() {} }
struct NoFoo {}
struct CallsFoo(T) {
T t;
void bar() { t.foo(); }
}
static assert(is(CallsFoo!HasFoo));
alias Bar = CallsFoo!HasFoo;
static assert(is(CallsFoo!NoFoo)); // (1)
//alias Baz = CallsFoo!NoFoo; // (2)
----
This compiles, although I expected that (1) should fail.
Now try uncommenting (2) and it can't be compiled.
Why does `is(CallsFoo!NoFoo)` evaluate to true if
`is(CallsFoo!NoFoo)`
can't be instantiated?
Am I missing something about `is(T)` or is it a bug?
How can I reliably test if CallsFoo can be instantiated?
is(T) is supposed to be false if T is not a valid type.
I would agree with you that the static assert should fail.
-Steve
Oh, there's more:
// this should fail:
static assert(is(CallsFoo!NoFoo));
// this should fail too:
static assert(is(typeof({ alias Baz = CallsFoo!NoFoo; return
Baz.init; }())));
// and this:
static assert(__traits(compiles, { alias Baz = CallsFoo!NoFoo;
return Baz.init; }()));
// but only this fails:
alias Baz = CallsFoo!NoFoo;
https://issues.dlang.org/show_bug.cgi?id=15623