Mixim template can only introduce declarations, not statements, a workaround is a lambda called in place. mixin template test(A...){ __gshared a = A; int dummy = (){ a++; return 0; }(); } extern(C) void main(){ mixin test!123; }