]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: unifying LAMBDA_EXPR [PR122318]
authorPatrick Palka <ppalka@redhat.com>
Tue, 17 Feb 2026 16:21:42 +0000 (11:21 -0500)
committerPatrick Palka <ppalka@redhat.com>
Tue, 17 Feb 2026 16:21:42 +0000 (11:21 -0500)
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 <jason@redhat.com>
gcc/cp/pt.cc
gcc/testsuite/g++.dg/cpp2a/lambda-targ20.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/lambda-targ21.C [new file with mode: 0644]

index 1d11b07d567dcb39d7e9a65c844887cab6bfaa9f..5db46cd707f164ccb6c9bbc141d8f5ef5e5dba61 100644 (file)
@@ -26650,6 +26650,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 (file)
index 0000000..4d444bb
--- /dev/null
@@ -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 (file)
index 0000000..d417d6c
--- /dev/null
@@ -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" }