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

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 29 08:36:01 PST 2016


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


More information about the Digitalmars-d-learn mailing list