is(some template instantiation) is true, but the actual instantiation fails

Adrian Matoga via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 29 07:28:29 PST 2016


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?



More information about the Digitalmars-d-learn mailing list