Comparing class references with null or other classes causes an error in CTFE, e.g.: module test; class C { int x; } int getA() { C c = new C; if(c is null) return -1; return c.x; } static assert(getA() == 0); Compiling with "dmd -c test.d" yields: test.d(11): Error: cannot compare C(0) at compile time test.d(16): called from here: getA() test.d(16): while evaluating: static assert(getA() == 0) if you use "if(c)" instead of "if(c is null)", the error itself disappears, there is only the call stack left: test.d(16): called from here: getA() test.d(16): while evaluating: static assert(getA() == 0) Using "if(!c)" seems to work.
https://github.com/D-Programming-Language/dmd/commit/767708299a408b4a234ee9ad4f45b0e6e0c21e6d https://github.com/D-Programming-Language/dmd/commit/13195c39ae3e3788c559d8e88d3203371e43f029