Fix segfault with undefined template declaration errors