D safety! New Feature?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 6 04:01:13 PDT 2016


On 06.08.2016 07:56, ag0aep6g wrote:
>
> Add parentheses to the typeof one and it fails as expected:
>
>     static assert(is(typeof(a.foo()))); /* fails */
>
> Can also do the function literal thing you did in the __traits one:
>
>     static assert(is(typeof(() { a.foo; }))); /* fails */

You can, but don't.

class A {
     int foo() { return 1; }
}

void main() {
     auto a = new A;
     static void gotcha(){
         // This passes:
         static assert(is(typeof((){a.foo;})));
         // This doesn't:
         static assert(__traits(compiles,(){a.foo;}));
     }
}



More information about the Digitalmars-d mailing list