Inside Sema::tryCaptureVariable, there is an unconditional cast from a FunctionScopeInfo to a CapturingScopeInfo. With a mixture of lambdas and variadic template, we can arrive at this point with a FunctionScopeInfo that is not a CapturingScopeInfo. This is the simple fix of bailing out early with a default return value.
This fixes https://github.com/llvm/llvm-project/issues/56071 plus another test case reduction I found.
I'm not certain whether this is indicative of a deeper issue where we expect to get a capturing scope and we're not, but the early return seems surprising. I would have guessed that we'd want to continue so that we loop around again and continue to try to capture the variable.