diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 0f4fb258f9ebc28fafd5d0bbd67b4114590783c0..ee4a2f31343015f61a40221cb6da2fe16d5fb4ef 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -7880,7 +7880,8 @@ coerce_template_args_for_ttp (tree templ, tree arglist,
   else if (current_template_parms)
     {
       /* This is an argument of the current template, so we haven't set
-	 DECL_CONTEXT yet.  */
+	 DECL_CONTEXT yet.  We can also get here when level-lowering a
+	 bound ttp. */
       tree relevant_template_parms;
 
       /* Parameter levels that are greater than the level of the given
@@ -14614,7 +14615,7 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
 
 static tree
 tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
-		      tree lambda_fntype)
+		      tree lambda_fntype, tree lambda_tparms)
 {
   /* We can get here when processing a member function template,
      member class template, or template template parameter.  */
@@ -14704,8 +14705,10 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain,
   auto tparm_guard = make_temp_override (current_template_parms);
   DECL_TEMPLATE_PARMS (r)
     = current_template_parms
-    = tsubst_template_parms (DECL_TEMPLATE_PARMS (t), args,
-			     complain);
+    = (lambda_tparms
+       ? lambda_tparms
+       : tsubst_template_parms (DECL_TEMPLATE_PARMS (t), args,
+				complain));
 
   bool class_p = false;
   tree inner = decl;
@@ -14876,7 +14879,9 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
   switch (TREE_CODE (t))
     {
     case TEMPLATE_DECL:
-      r = tsubst_template_decl (t, args, complain, /*lambda*/NULL_TREE);
+      r = tsubst_template_decl (t, args, complain,
+				/*lambda_fntype=*/NULL_TREE,
+				/*lambda_tparms=*/NULL_TREE);
       break;
 
     case FUNCTION_DECL:
@@ -20121,12 +20126,24 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 		  ? DECL_TI_TEMPLATE (oldfn)
 		  : NULL_TREE);
 
+  tree tparms = NULL_TREE;
+  if (oldtmpl)
+    tparms = tsubst_template_parms (DECL_TEMPLATE_PARMS (oldtmpl), args, complain);
+
   tree fntype = static_fn_type (oldfn);
+
+  tree saved_ctp = current_template_parms;
   if (oldtmpl)
-    ++processing_template_decl;
+    {
+      ++processing_template_decl;
+      current_template_parms = tparms;
+    }
   fntype = tsubst (fntype, args, complain, in_decl);
   if (oldtmpl)
-    --processing_template_decl;
+    {
+      current_template_parms = saved_ctp;
+      --processing_template_decl;
+    }
 
   if (fntype == error_mark_node)
     r = error_mark_node;
@@ -20142,7 +20159,8 @@ tsubst_lambda_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 				 type_memfn_quals (fntype),
 				 type_memfn_rqual (fntype));
       tree inst = (oldtmpl
-		   ? tsubst_template_decl (oldtmpl, args, complain, fntype)
+		   ? tsubst_template_decl (oldtmpl, args, complain,
+					   fntype, tparms)
 		   : tsubst_function_decl (oldfn, args, complain, fntype));
       if (inst == error_mark_node)
 	{
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-ttp1.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-ttp1.C
new file mode 100644
index 0000000000000000000000000000000000000000..27b56fc199c4657ed3c1fdf0c32709a5c3eb115f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-ttp1.C
@@ -0,0 +1,11 @@
+// PR c++/109651
+// { dg-do compile { target c++20 } }
+
+template<class T>
+void f() {
+  []<class U>(U) {
+    []<template<class> class TT>(TT<int>) { };
+  }(0);
+}
+
+template void f<int>();
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic-ttp2.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-ttp2.C
new file mode 100644
index 0000000000000000000000000000000000000000..dc2029d7227e63ac6ebc1e85d90a8d7059adc508
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic-ttp2.C
@@ -0,0 +1,13 @@
+// PR c++/109651
+// { dg-do compile { target c++20 } }
+
+template<class T>
+auto f() {
+  return []<class U, template<class V, U, V> class TT>(U, TT<int, 1, 2>) { };
+}
+
+template<class T, int N, int M> struct A { };
+
+int main() {
+  f<int>()(0, A<int, 1, 2>{});
+}