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
I find this function a bit confusing I would just move its body inline where it is currently called.
Although actually could this code be moved to where we do similar check for static or extern
https://clang.llvm.org/doxygen/SemaDecl_8cpp_source.html#l07911
You would then need to change this slightly i.e. to call VarDecl::getTSCSpec instead.