This fixes PR28795.
https://llvm.org/bugs/show_bug.cgi?id=28795
Sema wasn't replacing DependentScopeDeclRefExpr with DeclRefExpr during template instantiation of the default argument of the lambda function because it failed to find the instantiated enum "foo" in LocalInstantiationScope. This patch fixes the bug by allowing it to search the outer scope (function func).
The code does not seem to be the best solution. It assumes that if instantiation of a variable is requested, its arguments define all parameters needed to instantiate code. It is not so for the code:
This problem is caused by different nature of variable templates. When instantiating a function or a class all instantiated entities go to the contexts defined by the class or the function respectively. A variable does not represent a declaration context and its initializer and all declarations created during the instantiation go to enclosing context. So logic in getTemplateInstantiationArgs does not work.
May be we should extend the logic of getTemplateInstantiationArgs so that it supports variable template and still remains recursive?