https://gcc.gnu.org/g:1a1a34217e5989d5e5d6e4c546b404108527a0c6

commit r14-12701-g1a1a34217e5989d5e5d6e4c546b404108527a0c6
Author: Patrick Palka <[email protected]>
Date:   Tue Feb 17 11:21:42 2026 -0500

    c++: unifying LAMBDA_EXPR [PR122318]
    
    This patch makes the default case of unify accept LAMBDA_EXPR P/A pairs,
    which we can legitimately hit during alias CTAD guide overload resolution.
    We can also less legimitately hit this during partial specialization
    matching (likely IFNDR).
    
    I'm not totally sure if we want to handle them like any other non-deducible
    expression vs handling them separately (returning success iff they're ==).
    I couldn't come up with a testcase for which it mattered so I went the
    simpler route.
    
            PR c++/122318
            PR c++/101670
    
    gcc/cp/ChangeLog:
    
            * pt.cc (unify) <default>: Accept LAMBDA_EXPR.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/lambda-targ20.C: New test.
            * g++.dg/cpp2a/lambda-targ21.C: New test.
    
    Reviewed-by: Jason Merrill <[email protected]>
    (cherry picked from commit 9fe46ba8eb3f2cf41744cf8490b025f0876b9c86)

Diff:
---
 gcc/cp/pt.cc                               |  1 +
 gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C | 14 ++++++++++++++
 gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C | 10 ++++++++++
 3 files changed, 25 insertions(+)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 341b08ad3ebc..3ba1fb944b34 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -25495,6 +25495,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, 
int strict,
        return unify_success (explain_p);
       gcc_assert (EXPR_P (parm)
                  || TREE_CODE (parm) == CONSTRUCTOR
+                 || TREE_CODE (parm) == LAMBDA_EXPR
                  || TREE_CODE (parm) == TRAIT_EXPR);
     expr:
       /* We must be looking at an expression.  This can happen with
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C
new file mode 100644
index 000000000000..4d444bbe1121
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C
@@ -0,0 +1,14 @@
+// PR c++/122318
+// { dg-do compile { target c++20 } }
+
+template<class T, auto V>
+struct A {
+  A() { }
+  A(T) { }
+};
+
+template<class T>
+using AT = A<T, []{}>;
+
+AT<int> a;
+AT b = a;
diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C 
b/gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C
new file mode 100644
index 000000000000..d417d6cc3e85
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C
@@ -0,0 +1,10 @@
+// PR c++/101670
+// { dg-do compile { target c++20 } }
+
+template<int N, auto = []{}>
+struct A;
+
+template<int N>
+struct A<N> { }; // Partial specialization unusable due to lambda uniqueness
+
+A<0> a; // { dg-error "incomplete" }

Reply via email to