For templates diagnosis must be done after specialization instead of during parsing.
I've left the check during parsing as well, because it provides slightly better error messages, though some are lost now that NewVD is set as invalid, instead of just setting D invalid.
This fixes: https://bugs.llvm.org/show_bug.cgi?id=48887