According to 7.5.6 [expr.prim.lambda] paragraph 3,
The closure type is declared in the smallest block scope, class scope, or namespace scope that contains the corresponding lambda-expression. [Note: This determines the set of namespaces and classes associated with the closure type (6.5.4 [basic.lookup.argdep]). The parameter types of a lambda-declarator do not affect these associated namespaces and classes. —end note]
However, 13.9.2 [temp.inst] paragraph 13 says,
If a function template f is called in a way that requires a default argument to be used, the dependent names are looked up, the semantics constraints are checked, and the instantiation of any template used in the default argument is done as if the default argument had been an initializer used in a function template specialization with the same scope, the same template parameters and the same access as that of the function template f used at that point.
A possibility, then, is that the closure type for a lambda expression in a default argument for a template function (or, presumably, a member function of a class template) is to be considered as having been declared in some block scope in the body of the fictional function template specialization.
Consider the following example:
namespace J { inline namespace K { template <typename T> int zap(const T &t) { foo(t); return 0; } template <typename T> void zip(int = zap([] { })) { } } template <typename T> void foo(const T &) { } } void bar() { J::K::zip<long>(); }
If zip were not a template, argument-dependent lookup successfully resolves the lookup for foo in all implementations tested; however, there is implementation variance in the handling of the example as written.
(See also issue 1690.)