Mark the arguments to a template as @trusted if they are not safe, and the template will then be safe. The real issue here is too much unsafe code. There isn't a way to fix that without rolling up one's sleeves and going after it hammer and tong.