Index: lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiate.cpp +++ lib/Sema/SemaTemplateInstantiate.cpp @@ -2913,6 +2913,9 @@ // error recovery. if (isa(D)) return nullptr; + if (const VarDecl *VD = dyn_cast(D)) + if (VD->isInitCapture()) + return nullptr; // If we didn't find the decl, then we either have a sema bug, or we have a // forward reference to a label declaration. Return null to indicate that Index: lib/Sema/SemaTemplateInstantiateDecl.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiateDecl.cpp +++ lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4962,6 +4962,14 @@ return cast(Inst); } + // If the variable is in InitCapture and variable types are of type + // mentioned in the above comment (the comment starting as "Normally + // this function...") then its existance won't be known so we have to + // make an exclusion for them. + if (const VarDecl *VD = dyn_cast(D)) + if (VD->isInitCapture()) + return nullptr; + // If we didn't find the decl, then we must have a label decl that hasn't // been found yet. Lazily instantiate it and return it now. assert(isa(D)); Index: test/SemaCXX/lambda-init-capture-vardefine.cpp =================================================================== --- /dev/null +++ test/SemaCXX/lambda-init-capture-vardefine.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s +// expected-no-diagnostics + +template using a = void; +template struct c { static const int d = b; }; +template > struct e : c {}; +template g h(int); +template decltype(h(0)) i; +template struct e())>>; +template auto func(k &&); +template struct l { + template static auto n(k o) { + return [f{o}](auto) { func([](auto...) -> decltype(f) {}); }; + } +}; +template auto func(k &&o) { return l::d>::n(o); } +int main(void) { + auto f = [](auto) {}; + func(f)(1); +}