This looks like a correct D2 program: import std.string: split; template Foo(alias items) { static if (items.length == 0) enum Foo = 1; else enum Foo = 2; } enum string[] items = split(""); static assert(Foo!(items) == 1); void main() {} But DMD v2.046 prints at compile-time: test.d(3): Error: expression (null.length) == 0u is not constant or does not evaluate to a bool test.d(9): Error: template instance test.Foo!(items) error instantiating test.d(9): Error: static assert (2 == 1) is false ------------------------ To fix it you have to test for null too: import std.string: split; template Foo(alias items) { static if (items == null || items.length == 0) enum Foo = 1; else enum Foo = 2; } enum string[] items = split(""); static assert(Foo!(items) == 1); void main() {}
https://github.com/D-Programming-Language/dmd/pull/365
https://github.com/D-Programming-Language/dmd/commit/4ff28a3be1a35013cb6046b21c43a55f1b87f676 https://github.com/D-Programming-Language/dmd/commit/70174180cbfc83c9cde9d745ca367b08b49af398