Don't allow lambdas to capture invalid decls during template instantiations.

Fixes PR20731.